2017-10-31 15 views
0

양식 테이블이 있고 각 행에 select2가 포함되어 있습니다. 각 데이터를 가져 와서 배열에 저장하고 싶습니다. 아래는 올바른 사용법이 확실하지 않을 때 사용할 코드입니다.Select2 - 루프에서 데이터 가져 오기

// event on each form change re-get the values 
     $("#main").bind("keyup change", function (e) { 


         $('#form > tbody > tr').each(function (i) { 

     // get the data for each select 
     // add it to array and use after loop for some logic 
     // not sure if need this event here : select2:select 
     // also the selector might be not in the node of current tr? 

          $('.selector').on("select2:select", function (e) { 

           var data = $(this).select2('data'); 

           // push to array ?? data[0].custom_data 

          }); 

         }); 

    // logic from array would be here 

        }); 
+0

$('.selector').on("select2:select", function (e) { var data = $(this).select2('data'); // push to array ?? data[0].custom_data }); 

가이 코드를 실행 않았다 교체

TR에서 필요한 요소를 발견해야한다, 당신은 어떤 오류가 발생 했습니까? 조금 더 자세한 내용이 도움이 될 것입니다 –

+0

글쎄, 그것은 단지 하나의 행을 가져옵니다.] –

답변

3

당신은 예 경우,

var data = $(this).find('.selector').select2('data'); 
+0

예, 그렇게 생각했습니다. –