2017-03-08 30 views
0

的JavaScript天才的存在,中的JavaScript的LiveCycle - 对象

期望的结果是为“建议”和“授权”显示,如果任一两个复选框被选中。

/*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"; 
} 

如果我选中一个复选框,则会显示所需的“推荐”和“授权”对象。如果我选中两个复选框,然后取消选中一个,隐藏“推荐”和“授权”对象。其他基金的复选框在表单上有不同的审批要求。

是什么导致了这个问题?什么解决它?什么是更清晰的编写代码的方式?所有的指导表示赞赏。

回答

0
  1. 创建脚本对象来存储所有的util函数,并给它一个简洁的名字。
  2. 在那里你应该创建函数来使对象可见和不可见。这不是强制性的,但这种结构会减少愚蠢的错误数目(如单词“看得见”等缺少一些字母):

    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. 设置需要国家授权和recomended对象创建类函数:

    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. 在CheckBox1的Click事件中调用设置auth的方法。和rec。州。并为Fund1对象设置可见性。

    Lib.setStateAuth(); 
    Lib.setStateRec(); 
        if(this.rawValue == "1"){ 
         Lib.setVisible(Fund1); 
        }else{ 
         Lib.setInvisible(Fund1); 
        } 
    
  5. 在CheckBox2的Click事件中调用设置auth的方法。和rec。州。并为Fund2对象设置可见性。

    Lib.setStateAuth(); 
    Lib.setStateRec(); 
        if(this.rawValue == "1"){ 
    Lib.setVisible(Fund2); 
        }else{ 
    Lib.setInvisible(Fund2); 
    } 
    
  6. 注意,不推荐使用“resolveNode”方法的对象的工作(由于性能问题)。所以,如果你有一个简洁而不是动态的页面数量,最好命名所有的页面,并用它们的名字来引用它们。就像它是在样品中完成的,我做了

Here you can get a sample PDF