单击多个复选框时删除记录

我想删除在复选框中选中的记录,同时也删除了整条记录。


这是用户可以选择全选复选框的选项卡。


<button type="checkbox" id="checkall" class="btn btn-default btn-sm checkbox-toggle">

    <i class="fa fa-square-o" ></i>

</button>

<div class="btn-group">

    <button type="submit" class="btn btn-default btn-sm" >

        <i class="fa fa-trash-o"></i>

    </button>

</div>


<!-- /.btn-group -->

<a href="{{ route('home.notificationbox') }}">

    <button type="button" class="btn btn-default btn-sm">

        <i class="fa fa-refresh"></i>

    </button>

</a>

这是表结构


<div class="table-responsive mailbox-messages">

    <table id="mailplan" class="table table-hover-row table-striped-row{{ count($admin_notifications) > 0 ? 'datatable' : '' }}" data-page-length="25">

        <tbody>

            @if (count($admin_notifications) > 0)


                <?php $count=1; ?>

                @foreach ($admin_notifications as $admin_notification)


                    @if($admin_notification['is_read'] == 1)            

                        <tr class="table-dark-row" data-entry-id="{{ $admin_notification['notification_id'] }}">

                            <td>

                                <a href="">{{ $count++ }}</a>

                            </td>

                            <td>

                                <input type="checkbox" class="checkbox" 

                                    onclick="delete_admin_notification({{ $admin_notification['notification_id'] }});"

                                    name = "deleteMultipleMail[]" 

                                    value = "{{ $admin_notification['notification_id' ]}}">

                            </td>


这是删除,控制器。

Route::post('/deleteMultipleMail','HomeController@deleteMultipleMail');

单击复选框删除所有记录或仅选择将被删除的记录。


茅侃侃
浏览 103回答 1
1回答

繁华开满天机

在你的 js 文件中:$('.delete-all').on('click', function(e) {&nbsp; &nbsp; var idsArr = [];&nbsp;&nbsp; &nbsp; $('.checkbox').each(function(){&nbsp; &nbsp; &nbsp; &nbsp; var isChecked = $(this).prop('checked');&nbsp; &nbsp; &nbsp; &nbsp; if(isChecked){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idsArr.push($(this).val());&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; $.ajaxSetup({&nbsp; &nbsp; &nbsp; &nbsp; headers: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; url: "/deleteMultipleMail",&nbsp; &nbsp; &nbsp; &nbsp; type: 'POST',&nbsp; &nbsp; &nbsp; &nbsp; data:{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idsArr: idsArr&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; success: function (response) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(response.success){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;window.location = response.redirect_url;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('Whoops Something went wrong!!');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; error: function (data) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(data.responseText);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });});在您的控制器中:public function deleteMultipleMail(Request $request){&nbsp; &nbsp; $post = $request->all();&nbsp; &nbsp; AdminNotification::whereIn('notification_id' , $post['idsArr'])->delete();&nbsp; &nbsp; return response()->json(['success' => true, 'redirect_url' => 'your redirect url']);}
打开App,查看更多内容
随时随地看视频慕课网APP