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]);
}
添加回答
举报
0/150
提交
取消