2017-03-08 8 views
0

자바 스크립트 천재 객체의 존재,자바 스크립트 -

원하는 결과는 "권장"두 확인란 중 하나를 선택하는 경우 "승인"보여주기위한 것입니다.

/*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 함수를 저장하고 concrate 이름을 부여하기 위해 스크립트 객체를 만듭니다.
  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. 권한 부여 및 시스템 권장 객체에 필요한 상태를 설정 fucntions 만들기 :

    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 이벤트에서. 및 rec. 상태. 또한 Fund1 오브젝트에 대한 가시성을 설정합니다. 인증 설정에 대한 CheckBox2 호출 방법의 클릭 이벤트에서

    Lib.setStateAuth(); 
    Lib.setStateRec(); 
        if(this.rawValue == "1"){ 
         Lib.setVisible(Fund1); 
        }else{ 
         Lib.setInvisible(Fund1); 
        } 
    
  5. . 및 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