2012-05-08 1 views
2

나는 datatables으로 애 쓰고 fnGetNodes과 어떻게 관련이있어 제출시 데이터를 올바르게 다시 푸시합니다.Datatables - fnGetNodes() 결과를 서버로 다시 푸시하는 방법

jquery가 제대로 작동하고 있습니다. documentation에 설명 된대로 선택한 값을 볼 수 있습니다. 내 질문은 어떻게 그 sData 걸리고 그 POST 서버에 다시 밀어?

나는 그것이 단순해야한다라는 것을 알고있다. 그러나 나는 숲을보기 위해 나무에 명확히 너무 집중했다.. 나는 이것에 관해 어떤 도움이라도 감사 할 것이다!!

<script style="text/javascript"> 

    $(document).ready(function() { 
     $('#form').submit(function() { 
      var sData = $('input', oTable.fnGetNodes()).serialize(); 
      alert("The following data would have been submitted to the server: \n\n"+sData); 
      return false; 
     }); 

     oTable = $('#data_table').dataTable(); 
    }); 
</script> 

내 HTML 양식

<table id="data_table"> 
      <thead> 
       <tr> 
        <th>Select</th> 
        <th>Question</th> 
       </tr> 
      </thead> 
      <tr id=0><td><label for="id_questions_0"><input type="checkbox" name="questions" value="103" id="id_questions_0" /></label></td><td>D1. Example of a multiple choice question</td></tr> 
<tr id=1><td><label for="id_questions_1"><input type="checkbox" name="questions" value="104" id="id_questions_1" /></label></td><td>E1. Example of a multiple choice question</td></tr> 
<tr id=2><td><label for="id_questions_2"><input type="checkbox" name="questions" value="105" id="id_questions_2" /></label></td><td>G. Example of a multiple choice question</td></tr> 
<tr id=3><td><label for="id_questions_3"><input type="checkbox" name="questions" value="106" id="id_questions_3" /></label></td><td>H. Example of a multiple choice question</td></tr> 

편집

경고 나이를 보여주고있다 (명확성을 위해 단축)과 같습니다. questions=103&questions=104&questions=105&questions=106&questions=100&questions=101&questions=102

그리고 (개발자 도구를 사용하여 POST가 (나를이 보이고있다.

csrfmiddlewaretoken:a2c3ed6e1bfee9fce0b7412553aa2080 
name:Phase-1 Pre-Drywall 
priority:1 
description:Pre-Drywall inspection items 
use_for_confirmed_rating:on 
use_for_sampling:on 
data_table_length:10 
questions:103 
questions:104 
questions:105 
questions:106 
submit:Submit 

그래서 어떻게 든 사람이 나를 도울 수 나중에 사용 JQuery와에 전자를 변환해야합니다.

감사

답변

3

는 대답은 매우 단순하게 (예상대로) 밝혀졌다.

 var oTable = $('#data_table').dataTable(); 
     // This will collect all of the nodes which were checked and make sure they get 
     // pushed back. 
     $('#form').submit(function() { 
      $("input[name='question']").remove(); //Remove the old values 
      $("input:checked", oTable.fnGetNodes()).each(function(){ 
       $('<input type="checkbox" name="questions" ' + 'value="' + 
        $(this).val() + '" type="hidden" checked="checked" />') 
        .css("display", "none") 
        .appendTo('#form'); 
      }); 
     }); 
관련 문제