简体   繁体   English

LiveCycle中的JavaScript-对象的存在

[英]JavaScript in LiveCycle - Presence of Objects

JavaScript Geniuses, JavaScript天才,

The desired result is for "recommend" and "authorization" to show if either of the two checkboxes are checked. 期望的结果是用于“推荐”和“授权”以显示是否选中两个复选框中的任何一个。

/*For Checkbox1: Fund1 */
if (this.rawValue == "1") {
  this.resolveNode("fund1").presence = "visible";
  this.resolveNode("recommend").presence = "visible";
  this.resolveNode("authorization").presence = "visible";
} else {
  this.resolveNode("fund1").presence = "hidden";
  this.resolveNode("recommend").presence = "hidden";
  this.resolveNode("authorization").presence = "hidden";
}

/*For Checkbox2 - Fund2: */
if (this.rawValue == "1") {
  this.resolveNode("fund2").presence = "visible";
  this.resolveNode("recommend").presence = "visible";
  this.resolveNode("authorization").presence = "visible";
} else {
  this.resolveNode("fund2").presence = "hidden";
  this.resolveNode("recommend").presence = "hidden";
  this.resolveNode("authorization").presence = "hidden";
}

If I check one checkbox, the required "recommend" and "authorization" objects are visible. 如果我选中一个复选框,则可见所需的“推荐”和“授权”对象。 If I check both checkboxes then uncheck one, the "recommend" and "authorization" objects hide. 如果同时选中两个复选框,则取消选中它们,则“推荐”和“授权”对象将隐藏。 There are checkboxes for other funds that have a different approval requirement on the form. 其他基金的复选框在表单上有不同的批准要求。

What causes the issue? 是什么原因引起的? What resolves it? 有什么解决的办法? What is a cleaner way to write the code? 什么是更干净的代码编写方式? All guidance is appreciated. 感谢所有指导。

  1. Create Script Object to store all your util functions and give it a concrate name. 创建脚本对象以存储所有util函数,并为其指定一个简洁的名称。
  2. There you should create functions for making an object visible and invisible. 在那里,您应该创建使对象可见和不可见的函数。 This is not mandatory, but such structure will reduce the number of stupid mistakes (like missing some letters in the word "visible" and so on): 这不是强制性的,但是这样的结构将减少愚蠢的错误(例如,在“可见”一词中缺少一些字母等等):

     function setVisible(field){ if (field === null) { //do what ever you want with an error } if (field === undefined) { //do what ever you want with an error } if (field instanceof Array) { //do what ever you want with an error } field.presence = "visible"; } function setInvisible(field){ if (field === null) { //do what ever you want with an error } if (field === undefined) { //do what ever you want with an error } if (field instanceof Array) { //do what ever you want with an error } field.presence = "invisible"; } 
  3. Create fucntions for setting needed states for authorization and recomended objects: 创建功能以设置授权和推荐对象的所需状态:

     function setStateAuth(){ if(Page1.CheckBox1.rawValue == "1" || Page1.CheckBox2.rawValue == "1"){ setVisible(Page1.Authorization); }else{ setInvisible(Page1.Authorization); } } function setStateRec(){ if(Page1.CheckBox1.rawValue == "1" || Page1.CheckBox2.rawValue == "1"){ setVisible(Page1.Recommend); }else{ setInvisible(Page1.Recommend); } } 
  4. In the click event of your CheckBox1 call methods for setting auth. 在CheckBox1的click事件中,用于设置身份验证的调用方法。 and rec. 和建议。 state. 州。 And also set visibility for Fund1 object. 并设置Fund1对象的可见性。

     Lib.setStateAuth(); Lib.setStateRec(); if(this.rawValue == "1"){ Lib.setVisible(Fund1); }else{ Lib.setInvisible(Fund1); } 
  5. In the click event of your CheckBox2 call methods for setting auth. 在CheckBox2的click事件中,用于设置身份验证的调用方法。 and rec. 和建议。 state. 州。 And also set visibility for Fund2 object. 并设置Fund2对象的可见性。

     Lib.setStateAuth(); Lib.setStateRec(); if(this.rawValue == "1"){ Lib.setVisible(Fund2); }else{ Lib.setInvisible(Fund2); } 
  6. Note, that working with objects using "resolveNode" method is not recommended (due to the performance issues). 注意,不建议使用“ resolveNode”方法处理对象(由于性能问题)。 So, if you have a concrate, not dynamic number of pages, it is better to name then all and refer to them using their names. 因此,如果您有一个紧凑的页面而不是动态的页面,则最好先命名所有页面,然后使用它们的名称来引用它们。 Like it is done in a sample, i've made 就像在样本中完成一样,

Here you can get a sample PDF 在这里您可以获取样本PDF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM