如何将Jquery中的复选框值数组发送到ASy Symfony

时间:2016-08-13 11:52:03

标签: jquery symfony

大多数项目都说依赖于使用JS(我是使用JS的初学者)。

所以在我的项目中(我使用的是技术SF 2.7),我将我的BD数据发布到表格中,为每行分配了一个“复选框”按钮和一个在表格标题中找到的“CheckAll”按钮,用于选择我的数据线。

在谷歌上搜索之后,我得到了第一个操作CheckAll,也就是说,当我点击“CheckAll”按钮时,将选择所有按钮。

唯一的问题是如何检索和发送id(我说的是复选框的值)到我的路径“deleteAll” 例如,如果我选择了两个bontons,那么我必须有两个id用于删除。

我的代码html:

<!-- menu dropdown-->

<form id="deleteAll" method="post" action="{{ path('deleteAll') }}">
    <strong>
        <i class="fa fa-trash" ></i> Delete
    </strong>
    <!-- ./menu dropdown -->

    <!-- table -->
    <table id="datatable" class="table table-hover">
        <thead>
            <tr>
                <th>
                    <input type="checkbox" id="checkAll" />
                    <!-- ici le bouton checkAll-->
                </th>
                <th>
                    Project title
                </th>
                <th>
                    Date Added
                </th>
                <th>
                    Modification date
                </th>
            </tr>
        </thead>
        <tbody>
            {% for entity in entities %}

            <tr class="gradeC">
                <td>
                    <input type="checkbox" id="d" name="check[]" value=" {{ entity.id }}" />
                </td>
                <td>
                    <strong>{{ entity.ProjectTitle }}</strong>
                </td>
                <td>
                    <strong>{{ entity.dateAdd |date('d-m-Y') }} </strong>
                </td>
                <td>
                    <strong>{{  entity.dateModification| date('d-m-Y H:i:s') }}                                            </strong>
                </td>
            </tr>

            {% endfor %}
        </tbody>

    </table>

</form>

- 我的代码JS:

<script>
  $(document).ready(function(){

            $("#checkAll").click(function(){

                var checked_status = this.checked;

                $("input[name='check[]']").each(function(){

                    this.checked = checked_status;
                    var v = $("#d").val();

                    $('#deleteAll').on('submit', function (e){
                        e.preventDefault();
                        actiondesubsitution();
                    });
                });

            });
        });


    </script>
你能帮帮我吗?我是jQuery的初学者。

1 个答案:

答案 0 :(得分:0)

以下是解决方案:

1-我们必须添加提交按钮的表格。

2-更改了此代码

wchar_t

通过

$('#deleteAll').on('submit', function (e){ 
  ....
  });