javascript 在 Oracle ApEx 中设置更改其他文本项时文本字段的显示值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26062647/
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-10-28 05:26:23  来源:igfitidea点击:

Set display value of text field on change of other text item in Oracle ApEx

javascriptplsqltextfieldoracle-apex

提问by dante deo

I have an Oracle ApEx (version 4.2.5) database application with 1 "Home" type page displaying the current records in a table and a "DML Form" type page where you can insert/update/delete records to the same table. That is a generic "Report and Form" type application.

我有一个 Oracle ApEx(4.2.5 版)数据库应用程序,它有 1 个“主页”类型页面,显示表中的当前记录和一个“DML 表单”类型页面,您可以在其中向同一个表插入/更新/删除记录。这是一个通用的“报告和表单”类型的应用程序。

On the 2nd page, I want to set value of 4 text fields on change of a specific text field named P2_KOD. For that, I have created a dynamic action regarding that specific text field. I have set event to "Change", selection type to "Item(s)", item(s) to "P2_KOD" and left condition null (ie. "- No Condition -").

在第二页上,我想在更改名为 P2_KOD 的特定文本字段时设置 4 个文本字段的值。为此,我针对该特定文本字段创建了一个动态操作。我已将事件设置为“更改”,选择类型为“项目”,项目为“P2_KOD”,并且条件为空(即“- 无条件-”)。

Then I have added a true action to set values of 4 text fields. I have tried "Set Value" actions of both "PL/SQL Function Body" and "JavaScript Expression". But I could not manage to set display values of that 4 text field. I know that I can set the session values of that 4 text field since I see them in "Inserted" state with correct item values assigned in the "Seesion" info.

然后我添加了一个真正的动作来设置 4 个文本字段的值。我已经尝试了“PL/SQL 函数体”和“JavaScript 表达式”的“设置值”操作。但是我无法设置那 4 个文本字段的显示值。我知道我可以设置那 4 个文本字段的会话值,因为我看到它们处于“插入”状态,并且在“Seesion”信息中分配了正确的项目值。

What is wrong with my configuration?

我的配置有什么问题?

Edit#1: I have created the same scneario on apex.oracle.com. You can login with the following credentials and check out the "Application 76791 - Simple Rep & Form App". There is a dynamic action named "WHEN_DEPT_CHANGED" which should change the value of P2_COMM to 3 times the value of department.

编辑#1:我在 apex.oracle.com 上创建了相同的场景。您可以使用以下凭据登录并查看“Application 76791 - Simple Rep & Form App”。有一个名为“WHEN_DEPT_CHANGED”的动态操作,它应该将 P2_COMM 的值更改为部门值的 3 倍。

Workspace: DANTE_DEO
UN       : anonymous_developer
PW       : ad

回答by Dave Lyndon

You are getting the error:

你收到错误:

Uncaught TypeError: string is not a function 

For this JS in 'Execute JS Code':

对于“执行 JS 代码”中的这个 JS:

$x('P2_COMM').innerHTML = $x('P2_EMPNO').value() * 3;
$x('P2_COMM').value = $x('P2_EMPNO').value() * 3;

It's because .value() is not a function, it's like a property. Change to:

这是因为 .value() 不是一个函数,它就像一个属性。改成:

$x('P2_COMM').innerHTML = $x('P2_EMPNO').value * 3;
$x('P2_COMM').value = $x('P2_EMPNO').value * 3;

And you should be in business.

你应该做生意。

Handy hint: You can debug JS code in Apex (or anything) by using the console in Google Chrome (hit F12, navigate to console and refresh the page) or with the Firebug extension in Firefox.

方便的提示:您可以使用 Google Chrome 中的控制台(按 F12,导航到控制台并刷新页面)或使用 Firefox 中的 Firebug 扩展来调试 Apex(或任何东西)中的 JS 代码。

回答by Pars

Please look at page 3 or Tab name "Pars test" in your application, some changes reflected in page.

请查看应用程序中的第 3 页或选项卡名称“Pars test”,页面中反映了一些更改。

As follows, add dynamic action

如下,添加动态动作

Event: Change   
Selection type :Items  
items:P3_DEPTNO   
Action: Execute javascript Code   
Code:   
var x = $v("P3_DEPTNO");   
var x = parseInt(x) * 3;  
$s('P3_COMM', x);

which changes your P3_COMM value to 3 times to value of P3_DEPTNO you have entered one.

这将您的 P3_COMM 值更改为 3 倍到您输入的 P3_DEPTNO 值。

Check Page 3, application 76791 for demo.

查看第 3 页,应用程序 76791 以获取演示。