如何从 Javascript 访问 Oracle Apex 变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5482030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:22:01  来源:igfitidea点击:

How to access Oracle Apex variables from Javascript?

javascriptoracle-apex

提问by tonyf

I'm using Oracle APEX but am unsure how to access the following variables from an external javascript file that may be located on the app server or stored in Shared Components -> Static Files.

我正在使用 Oracle APEX,但不确定如何从外部 javascript 文件访问以下变量,该文件可能位于应用服务器上或存储在共享组件 -> 静态文件中。

:APP_ID
:APP_PAGE_ID
:APP_SESSION

How can I reference the values for each of the above from javascript (stored as a Static File)?

如何从 javascript(存储为静态文件)中引用上述每个值?

回答by Tony Andrews

These values get rendered on the page as hidden items like this:

这些值作为隐藏项目呈现在页面上,如下所示:

<input type="hidden" name="p_flow_id" value="4000" id="pFlowId" />
<input type="hidden" name="p_flow_step_id" value="4150" id="pFlowStepId" />
<input type="hidden" name="p_instance" value="6528421540413702" id="pInstance" />

so you can reference them as:

所以你可以将它们引用为:

$v('pFlowId') // APP_ID
$v('pFlowStepId') // APP_PAGE_ID
$v('pInstance') // SESSION

It's a pity they aren't named the same as the session state!

遗憾的是它们的名称与会话状态不同!

回答by Daniel Frech

Since APEX 5 you can also use apex.iteminstead of $v, as described here:

由于APEX 5你也可以使用apex.item代替$ V,描述在这里

apex.item('pFlowId').getValue() // APP_ID
apex.item('pFlowStepId').getValue() // APP_PAGE_ID
apex.item('pInstance').getValue() // APP_SESSION

Both $v and apex.item require that the "apex" namespace has already been loaded at the time you try to access the values. If you ever need to access them before that, you can also use JavaScript only instead:

$v 和 apex.item 都要求在您尝试访问值时已经加载了“apex”命名空间。如果您需要在此之前访问它们,您也可以仅使用 JavaScript:

document.getElementById('pFlowId').value; // APP_ID
document.getElementById('pFlowStepId').value; // APP_PAGE_ID
document.getElementById('pInstance').value; // APP_SESSION