2017-05-11 7 views
1

검도 UI 프레임 워크를 사용하여 웹 응용 프로그램을 개발하고 있습니다. HTML 파일은 다음과 같습니다. -검도 드롭 다운 목록 값이 클래스 선택자와 함께 표시되지 않습니다.

<div class="grand_parent"> 

    <div class="parent1"> 
     <div class="child1"></div> 
    </div> 

    <div class="parent2"> 
     <div class="child2"></div> 
    </div> 

</div> 

'grand_parent'클래스는 조건에 따라 반복됩니다. 이 'child1'및 'child2'클래스는 Kendo 드롭 다운 목록에 바인딩됩니다.

$(".child1").kendoDropDownList({ 
    dataTextField: "text", 
    dataValueField: "value", 
    dataSource: options1, 
    index: 0, 
}); 

$(".child2").kendoDropDownList({ 
    dataTextField: "text", 
    dataValueField: "value", 
    dataSource: options2, 
    change: onSelect, 
    index: 0, 
}); 


options1 = [ 
    {text:"Child1", value:1}, 
    {text:"Child2", value:2}, 
    {text:"Child3", value:3}, 
]; 

options2 = [ 
    {text:"newChild1", value:'5'}, 
    {text:"newChild2", value:'6'}, 
    {text:"newChild3", value:'7'}, 
]; 

function onSelect(e){ 
    var value = e.sender.value(); 
    switch (value) { 
     case 5: 
     case 6: 
     case 7: 

      // Printing a combination string of both drop downlist's selected value(Example: "5_1") 

      break; 

     default: 

      break; 
    } 
} 

내가 $(this.element).closest(".parent2").siblings(".parent1").find(".child1").data("kendoDropDownList").value();

을 사용 (첫 번째 행의 '자식 2 드롭 다운리스트를'변경에) 첫 번째 행 '자식 1 DropDownList로'가치를 얻을 value.To DropDownList로 얻을 수있는 문제가 있습니다 그러나 나는 오류가 발생했습니다 같은 다음 -

Uncaught TypeError: Cannot read property 'value' of undefined 

답변

1
이에 DOM 탐색 식을 변경

도와주세요 :

$(this.element).closest(".parent2").siblings(".parent1").find("div.child1").data("kendoDropDownList").value(); 

Here 실례를 찾을 수 있습니다.

기본적으로 find(.child1)은 2 개의 DOM 요소를 반환하므로 적절한 구성 요소에 도달하려면 해당 선택기를 수정해야합니다.