0

我正在尝试将一组行 ID 发送到控制器以进行批量更新,我想我已经完成了数组部分(我不擅长 jQuery,仍在学习)但我不知道如何发送到控制器包含要更新的行的 id 的数组。

这是我的树枝:

{% block javascripts %}
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(document).ready(function () {
    $('#selectall').click(function () {
        $('.selectedId').prop('checked', isChecked('selectall'));
    });
});
function isChecked(checkboxId) {
    var id = '#' + checkboxId;
    return $(id).is(":checked");
}
function resetSelectAll(id) {
    // if all checkbox are selected, check the selectall checkbox
    // and viceversa
    if ($(".selectedId").length == $(".selectedId:checked").length) {
        $("#selectall").attr("checked", "checked");
        var ids = [];
        ids.concat(id);
    } else {
        $("#selectall").removeAttr("checked");
         removeItem = id; 
         ids = jQuery.grep(arr, function(value) {
        return value != removeItem;
      });
    }

    if ($(".selectedId:checked").length > 0) {
        $('#edit').attr("disabled", false);
    } else {
        $('#edit').attr("disabled", true);
    }
}

    </script>
{% endblock %}

{% block body %}

<table>

                                <thead>
                                    <tr>
                                        <th><input type="checkbox" id="selectall"></th>
                                        <th>{{ 'general.date'|trans }}</th>
                                        <th>{{ 'general.order_number'|trans }}</th>
                                        <th>{{ 'general.description'|trans }}</th>
                                        <th>{{ 'general.company_name'|trans }}</th>
                                        <th>{{ 'general.name'|trans }}</th>
                                        <th>{{ 'form.status'|trans }}</th>
                                        <th>WinPoints</th>
                                    </tr>
                                </thead>
                                        {% for details in details %}
                                <tbody>
                                    <tr>

                                        <td><div align="center"><input type="checkbox" class="selectedId" name="selectedId" onclick="resetSelectAll({{details.id}});" /></div></td>
                                        <td>{{ details.date | date("m/d/Y") }}</td>
                                        <td>{{ details.order_number }}</td>
                                        <td>{{ details.description }}</td>
                                        <td>{{ details.company }}</td>
                                        <td>{{ details.name }}</td>
                                        <td>{{ details.status }}</td>
                                        <td>{{ details.winpoints }}</td>

                                    </tr>
                                </tbody>
                                        {% endfor %}

                            </table> 
<form action="{{ path('advd_group_batch_p_r_status') }}" method="post" {{ form_enctype(formBase) }}>
                                    {{ form_widget(form) }}
                                    <input class="input_button" type="submit" value="Procesar" />
                                </form>

{% endblock %}

有任何想法吗?另外,如果您在 jquery 代码上看到任何错误,请让我知道我做错了什么,我无法测试它,因为我不知道如何将数组发送到控制器。

感谢您为我提供的任何帮助。

4

2 回答 2

0
{% block javascripts %}
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>

$(document).ready(function () {
$('#selectall').click(function () {
    $('.selectedId').prop('checked', isChecked('selectall'));
});
});
function isChecked(checkboxId) {
var id = '#' + checkboxId;
return $(id).is(":checked");
}
function resetSelectAll(id) {
// if all checkbox are selected, check the selectall checkbox
// and viceversa
if ($(".selectedId").length == $(".selectedId:checked").length) {
    $("#selectall").attr("checked", "checked");
    var ids = [];
    ids.concat(id);
} else {
    $("#selectall").removeAttr("checked");
     removeItem = id;
     ids = jQuery.grep(arr, function(value) {
    return value != removeItem;
  });
}

if ($(".selectedId:checked").length > 0) {
    $('#edit').attr("disabled", false);
} else {
    $('#edit').attr("disabled", true);
}

}
$(function(){
 $('.input_button').click(function(){
  $.ajax({
   url:"advd_group_batch_p_r_status",
   dataType:'json',
    type:'post',
    data:$("#formC").serialize()
  });
 });
});

</script>
{% endblock %}

{% block body %}

<form action="{{ path('advd_group_batch_p_r_status') }}" method="post" {{ form_enctype(formBase) }} id="formC">

                        <table>

                            <thead>
                                <tr>
                                    <th><input type="checkbox" id="selectall"></th>
                                    <th>{{ 'general.date'|trans }}</th>
                                    <th>{{ 'general.order_number'|trans }}</th>
                                    <th>{{ 'general.description'|trans }}</th>
                                    <th>{{ 'general.company_name'|trans }}</th>
                                    <th>{{ 'general.name'|trans }}</th>
                                    <th>{{ 'form.status'|trans }}</th>
                                    <th>WinPoints</th>
                                </tr>
                            </thead>
                                    {% for details in details %}
                            <tbody>
                                <tr>

                                    <td><div align="center"><input type="checkbox" class="selectedId" name="selectedId" onclick="resetSelectAll({{details.id}});" /></div></td>
                                    <td>{{ details.date | date("m/d/Y") }}</td>
                                    <td>{{ details.order_number }}</td>
                                    <td>{{ details.description }}</td>
                                    <td>{{ details.company }}</td>
                                    <td>{{ details.name }}</td>
                                    <td>{{ details.status }}</td>
                                    <td>{{ details.winpoints }}</td>

                                </tr>
                            </tbody>
                                    {% endfor %}

                        </table>
                              {{ form_widget(form) }}
                                <input class="input_button" type="submit" value="Procesar" />
                            </form>
                    </div>
                </div>



                        </div>
                    </div>
                </div>

{% endblock %}
于 2013-08-15T15:49:58.710 回答
0

我的应用程序中有一个时事通讯表单,该表单使用以下 javascript 发布:

<script type="text/javascript">
    function subscribeButtonPressed() {

        $.post('{{path('mailchimp_subscribe')}}',
                {
                    EMAIL: $("#mce-EMAIL").val(),
                    listid: $("#listid").val()
                },
                function (response) {
                    ga('send', 'pageview', '{{ path('mailchimp_subscribe') }}');
                    console.log(response);
                    if (response.code == 100 && response.success) {//dummy check
                        var alert = '<div class="span12 padding20" id="formContainer">\n\
                                 <h1>Great!</h1>\n\
                                 </div>';
                        $('#formContainer').fadeOut('slow', function () {
                            $('#thanksContainer').append(alert).hide().fadeIn('slow');
                        });

                    }

                }, 'JSON');
    }

    $(document).ready(function () {
        $('#mc-embedded-subscribe')
                .click(function (event) {
                    var btn = $(this);
                    if ($("#mce-EMAIL").val() != "") {
                        event.preventDefault();
                        btn.button('loading');
                        subscribeButtonPressed();
                    }
                });



    });
</script>

我还通过谷歌分析记录事件并显示一些响应 html。但我想你明白了,只需将 $.post 与你想要发送到的路径一起使用。我选择表单的单个值,但您也可以只发送整个表单。

于 2013-08-15T17:09:31.150 回答