【问题标题】:Getting Theme Roller Config JSON in APEX在 APEX 中获取主题滚轮配置 JSON
【发布时间】:2019-10-03 07:09:33
【问题描述】:

我正在尝试从apex_application_theme_styles 表、theme_roller_config CLOB 列中获取当前主题配置 JSON,并在 JavaScript 函数中使用它。

我使用的代码实现如下:

  • pr_get_theme_configProcessing > Ajax Callback
declare
  c_trc_json clob;
  c_trc_json_vars clob;
begin
  select theme_roller_config into c_trc_json from apex_application_theme_styles where application_id = :APP_ID and upper(IS_CURRENT) like upper('Yes');
  apex_json.parse(c_trc_json);
  --dbms_output.put_line(apex_json.get_varchar2(p_path => 'vars')); -- for debugging purposes, but prints nothing
end;
  • getThemeConfig 函数在 Page > JavaScript > Function ... Declaration
function getThemeConfig() {
  var themeConfig = new htmldb_Get(null, &APP_ID., 'APPLICATION_PROCESS=pr_get_theme_config', &APP_PAGE_ID.);
  var themeConfigJson = themeConfig.get();
  return themeConfigJson;
}

调用时,getThemeConfig 返回空字符串,但应该返回 JSON。

为了更好地理解,下面是theme_roller_config 内部的示例(在每个\n 被替换为真正的新行之后)

{
  "customCSS": "/* custom CSS, should be discarded in this case, cause could contain a large multiline CSS code block */",
  "vars": {
    "@g_Accent-BG": "#008328",
    "@g_Link-Base": "#267373",
    "@g_Header-BG": "#007228",
    "@g_Accent-OG": "#fafafa",
    "@g_Header-FG": "#ddffdd",
    "@g_Region-BG": "#ffffff",
    "@g_Region-Header-BG": "#007228",
    "@g_Nav-BG": "#ffffff",
    "@g_Nav-Active-BG": "#aaaaaa",
    "@g_Actions-Col-BG": "#ebebeb",
    "@g_Body-Title-BG": "#ffffff",
    "@l_Left-Col-BG": "#ebebeb",
    "@g_Nav-FG": "#dddddd",
    "@g_Nav-Active-FG": "#ffffff",
    "@g_Button-BorderRadius": "4px",
    "@g_Form-BorderRadius": "4px",
    "@g_Body-Content-Max-Width": "auto",
    "@g_Focus": "#007228",
    "@g_Form-Item-BG": "#fefefe",
    "@g_Nav-Icon": "#1c1c1f",
    "@menu_Tabs-Active-Text": "#0a6a14",
    "@g_Container-BorderRadius": "4px",
    "@g_Body-BG": "#f0f0f0",
    "@l_Button-Primary-BG": "#fd8b43",
    "@l_Button-Danger-BG": "#e53835",
    "@l_Button-Warning-Text": "#a30b0b",
    "@l_Button-Success-BG": "#007228",
    "@l_Button-Success-Text": "#ffffff",
    "@g_Form-Item-FG": "#3e3e3e",
    "@l_Button-Primary-Text": "#5f3100"
  }
}

现在,主要问题:

  • 在 IDE 中调试我的 PL/SQL 时如何查看apex_json.parse 过程的结果(在我的例子中,它是PL/SQL Developer)?

  • 如何在PL/SQL中访问JSON的vars属性并将其传递给JavaScript函数?

【问题讨论】:

    标签: javascript plsql oracle-apex-5.1


    【解决方案1】:

    vars属性中获取对象的正确方法是在PL/SQL AJAX回调过程中使用apex_json.writeapex_json.g_values,并在JS中使用apex.server.process调用它。这是一个例子:

    • pr_get_theme_config in Processing > Ajax Callback:
    declare
      c_trc clob;
    begin
      select theme_roller_config 
        into c_trc 
        from apex_application_theme_styles 
        where application_id = :APP_ID 
          and upper(IS_CURRENT) like upper('Yes');
      apex_json.parse(c_trc);
      apex_json.write(apex_json.g_values, 'vars');
    end;
    
    • Page > JavaScript > Function ... Declaration:
    apex.server.process(
      'pr_get_theme_config',{},{
        success: function (data) {
          doSomething(JSON.parse(data));
        },
        dataType: 'text'}
    );
    

    使用apex.server.process 请记住,IE11 不支持 Promises,因此您应该使用success 属性进行回调。否则你可以在其他浏览器中使用.then()

    更多文档:

    1. APEX API Reference - APEX_JSON
    2. WRITE Procedure Signature 15
    3. Same question at Oracle Community

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-29
      • 2011-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多