在 APEX 中获取主题滚轮配置 JSON
Getting Theme Roller Config JSON in APEX
我正在尝试从 apex_application_theme_styles
table、theme_roller_config
CLOB 列中获取当前主题配置 JSON,并在 JavaScript 函数中使用它。
我使用的代码实现如下:
pr_get_theme_config
在 Processing
> 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
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"
}
}
现在,主要问题:
如何在 IDE 中调试我的 PL/SQL 时查看 apex_json.parse
过程的结果(在我的例子中,它是 PL/SQL Developer
)?
如何访问PL/SQL中JSON的vars
属性并将其传递给JavaScript函数?
从vars
属性获取对象的正确方法是在PL/SQLAJAX回调过程中使用apex_json.write
和apex_json.g_values
并使用 apex.server.process
从 JS 调用它。这是一个例子:
pr_get_theme_config
在 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()
。
更多文档:
我正在尝试从 apex_application_theme_styles
table、theme_roller_config
CLOB 列中获取当前主题配置 JSON,并在 JavaScript 函数中使用它。
我使用的代码实现如下:
pr_get_theme_config
在Processing
>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
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"
}
}
现在,主要问题:
如何在 IDE 中调试我的 PL/SQL 时查看
apex_json.parse
过程的结果(在我的例子中,它是PL/SQL Developer
)?如何访问PL/SQL中JSON的
vars
属性并将其传递给JavaScript函数?
从vars
属性获取对象的正确方法是在PL/SQLAJAX回调过程中使用apex_json.write
和apex_json.g_values
并使用 apex.server.process
从 JS 调用它。这是一个例子:
pr_get_theme_config
在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()
。
更多文档: