选择多个 id 并一次传递到控制器

ids我尝试从删除多个 id 的概念中选择多个,但收到错误并且 id 未通过


这是我尝试过的代码


  <button style="margin-bottom: 10px" class="btn btn-primary delete_all" data-url="{{ 

      url('receiveAllUnit') }}">Received All</button>

     $(document).ready(function () {



    $('#master').on('click', function(e) {

     if($(this).is(':checked',true))

     {

        $(".sub_chk").prop('checked', true);

     } else {

        $(".sub_chk").prop('checked',false);

     }

    });



    $('.delete_all').on('click', function(e) {



        var allVals = [];

        $(".sub_chk:checked").each(function() {

            allVals.push($(this).attr('data-id'));

        });



        if(allVals.length <=0)

        {

            alert("Please select row.");

        }  else {



            var check = confirm("Are you sure you want to Receive All Units?");

            if(check == true){



                var join_selected_values = allVals.join(",");



请告诉我如何获取这些 id 并将其传递给控制器


我希望更新这样的一栏


 RotateDevice::whereIn([ ['DeviceId',$ids]

                                        ])

                              ->update([

                                'status'=>0,

                              ]);


跃然一笑
浏览 48回答 1
1回答

郎朗坤

在 Ajax 调用中替换 Fromdata: 'ids='+join_selected_values,到data: {ids:join_selected_values},并在控制器中$idsString=$request->input('ids');$idsArray=explode(",",trim($idsString,','));//explode to split ids to array , and trim to ensure if ids received with , at the end or beginning of string.&nbsp;if(!empty($idsArray)){&nbsp; &nbsp; &nbsp;RotateDevice::whereIn('DeviceId',$idsArray)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->update(['status'=>0]);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript