【问题标题】:Datatables - fnGetNodes() how to push the results back to the serverDatatables - fnGetNodes() 如何将结果推送回服务器
【发布时间】:2012-05-08 05:01:51
【问题描述】:

我一直在努力处理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&amp;questions=104&amp;questions=105&amp;questions=106&amp;questions=100&amp;questions=101&amp;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 将前者转换为后者有人可以帮我解决这个问题

谢谢

【问题讨论】:

    标签: jquery webforms datatables


    【解决方案1】:

    结果(如预期的那样)答案非常简单。

            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');
                });
            });
    

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多