在 APEX 中获取主题滚轮配置 JSON

Getting Theme Roller Config JSON in APEX

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

我使用的代码实现如下:

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;
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 return是空字符串,但应该return 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"
  }
}

现在,主要问题:

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

  • pr_get_theme_configProcessing > 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. 写入程序签名 15
  3. Same question at Oracle Community