为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

跃然一笑 2023-10-14 19:26:02
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,                              ]);
查看完整描述

1 回答

?
郎朗坤

TA贡献1921条经验 获得超9个赞

在 Ajax 调用中替换 From


data: '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. 

if(!empty($idsArray)){

     RotateDevice::whereIn('DeviceId',$idsArray)

          ->update(['status'=>0]);

}


查看完整回答
反对 回复 2023-10-14
  • 1 回答
  • 0 关注
  • 46 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信