在删除表编辑js中的行后未删除表行

时间:2019-12-04 04:38:08

标签: jquery ajax edit-tableview

我正在尝试删除数据库的数据后删除表行。而且,我正在使用tableedit.js。我编写了以下代码来删除已删除的行,但是,它似乎不起作用:

$('.tabledit-confirm-button').click(function () {

                if(confirm("Are you sure, you want to delete this category?"))
                {
                    var data = $(this).closest('tr').find('input[type=hidden]').val();

                    var url = '{{ route("category.destroy", ":data") }}';

                    url = url.replace(':data', data);

                    $.ajax({
                        method: "POST",
                        url: url,
                        dataType: 'json',
                        data: { _token:"{{ csrf_token() }}", _method:"DELETE"},
                        success(response){

                            success(response.data);

                            $('.tabledit-deleted-row').remove();

                        },
                        error: function(response){
                            let data = response.responseJSON.errors;

                            $.each( data, function( key, value ) {
                                $( "<span class='validation-errors text-danger'>"+value+"</span>" ).insertAfter( "#"+key );
                            });
                        }
                    });
                }

            });

当我单击tableedit的确认按钮时,将添加类tabledit-deleted-row。从数据库删除数据后如何删除表行?

以下是我在html中的代码:

<table class="table table-striped table-bordered" id="example-1">
<thead>
    <tr>
        <th>#</th>
        <th>Name</th>
        <th>Is Parent</th>
        <th>Parent</th>
        <th class="tabledit-toolbar-column">Action </th>
    </tr>
</thead>
<tbody id="check">
    <tr>
        <th scope="row">1</th>
        <input type="hidden" value="6">
        <td class="tabledit-view-mode"><span class="tabledit-span">Colleen Soto

                                                        </span>
            <input class="tabledit-input form-control input-sm" type="text" name="name" value="Colleen Soto

                                                        " style="display: none;" disabled="">
        </td>
        <td class="tabledit-view-mode"><span class="tabledit-span">Yes 

                                                        </span>
            <input class="tabledit-input form-control input-sm" type="text" name="is_parent" value="Yes 

                                                        " style="display: none;" disabled="">
        </td>
        <td class="tabledit-view-mode"><span class="tabledit-span" style="">Colleen Soto</span>
            <select class="tabledit-input form-control input-sm" name="Nickname" style="display: none;" disabled="">
                <option value="6">Colleen Soto</option>
                <option value="9">Colleen Sotomjbj</option>
            </select>
        </td>
        <td style="white-space: nowrap; width: 1%;">
            <div class="tabledit-toolbar btn-toolbar" style="text-align: left;">
                <div class="btn-group btn-group-sm" style="float: none;">
                    <button type="button" class="tabledit-edit-button btn btn-primary waves-effect waves-light" style="float: none;margin: 5px;"><span class="icofont icofont-ui-edit"></span></button>
                    <button type="button" class="tabledit-delete-button btn btn-danger waves-effect waves-light" style="float: none;margin: 5px;"><span class="icofont icofont-ui-delete"></span></button>
                </div>
                <button type="button" class="tabledit-save-button btn btn-sm btn-success" style="display: none; float: none;">Save</button>
                <button type="button" class="tabledit-confirm-button btn btn-sm btn-danger" style="display: none; float: none;">Confirm</button>
                <button type="button" class="tabledit-restore-button btn btn-sm btn-warning" style="display: none; float: none;">Restore</button>
            </div>
        </td>
    </tr>
    <tr>
        <th scope="row">2</th>
        <input type="hidden" value="8">
        <td class="tabledit-view-mode"><span class="tabledit-span">Canosoft

                                                        </span>
            <input class="tabledit-input form-control input-sm" type="text" name="name" value="Canosoft

                                                        " style="display: none;" disabled="">
        </td>
        <td class="tabledit-view-mode"><span class="tabledit-span"> No 

                                                        </span>
            <input class="tabledit-input form-control input-sm" type="text" name="is_parent" value=" No 

                                                        " style="display: none;" disabled="">
        </td>
        <td class="tabledit-view-mode"><span class="tabledit-span" style="">Canosoft</span>
            <select class="tabledit-input form-control input-sm" name="Nickname" style="display: none;" disabled="">
                <option value="6">Colleen Soto</option>
                <option value="9">Colleen Sotomjbj</option>
            </select>
        </td>
        <td style="white-space: nowrap; width: 1%;">
            <div class="tabledit-toolbar btn-toolbar" style="text-align: left;">
                <div class="btn-group btn-group-sm" style="float: none;">
                    <button type="button" class="tabledit-edit-button btn btn-primary waves-effect waves-light" style="float: none;margin: 5px;"><span class="icofont icofont-ui-edit"></span></button>
                    <button type="button" class="tabledit-delete-button btn btn-danger waves-effect waves-light" style="float: none;margin: 5px;"><span class="icofont icofont-ui-delete"></span></button>
                </div>
                <button type="button" class="tabledit-save-button btn btn-sm btn-success" style="display: none; float: none;">Save</button>
                <button type="button" class="tabledit-confirm-button btn btn-sm btn-danger" style="display: none; float: none;">Confirm</button>
                <button type="button" class="tabledit-restore-button btn btn-sm btn-warning" style="display: none; float: none;">Restore</button>
            </div>
        </td>
    </tr>
    <tr>
        <th scope="row">3</th>
        <input type="hidden" value="9">
        <td class="tabledit-view-mode"><span class="tabledit-span">Colleen Sotomjbj

                                                        </span>
            <input class="tabledit-input form-control input-sm" type="text" name="name" value="Colleen Sotomjbj

                                                        " style="display: none;" disabled="">
        </td>
        <td class="tabledit-view-mode"><span class="tabledit-span">Yes 

                                                        </span>
            <input class="tabledit-input form-control input-sm" type="text" name="is_parent" value="Yes 

                                                        " style="display: none;" disabled="">
        </td>
        <td class="tabledit-view-mode"><span class="tabledit-span" style="">Colleen Sotomjbj</span>
            <select class="tabledit-input form-control input-sm" name="Nickname" style="display: none;" disabled="">
                <option value="6">Colleen Soto</option>
                <option value="9">Colleen Sotomjbj</option>
            </select>
        </td>
        <td style="white-space: nowrap; width: 1%;">
            <div class="tabledit-toolbar btn-toolbar" style="text-align: left;">
                <div class="btn-group btn-group-sm" style="float: none;">
                    <button type="button" class="tabledit-edit-button btn btn-primary waves-effect waves-light" style="float: none;margin: 5px;"><span class="icofont icofont-ui-edit"></span></button>
                    <button type="button" class="tabledit-delete-button btn btn-danger waves-effect waves-light" style="float: none;margin: 5px;"><span class="icofont icofont-ui-delete"></span></button>
                </div>
                <button type="button" class="tabledit-save-button btn btn-sm btn-success" style="display: none; float: none;">Save</button>
                <button type="button" class="tabledit-confirm-button btn btn-sm btn-danger" style="display: none; float: none;">Confirm</button>
                <button type="button" class="tabledit-restore-button btn btn-sm btn-warning" style="display: none; float: none;">Restore</button>
            </div>
        </td>
    </tr>
</tbody>

1 个答案:

答案 0 :(得分:1)

您可以尝试

将jquery import operator import csv import requests from bs4 import BeautifulSoup import re import json def write_output(data): with open('C:\\forex.csv', mode='w', encoding="utf-8") as output_file: writer = csv.writer(output_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) writer.writerow(["SYMBOL", "VOLATILITY","% CHANGE",""]) for row in sorted(data, key=lambda item: item[0]): writer.writerow(row) 对象保存到var中,然后使用该搜索并删除this。您的最终代码将类似于下面的代码

tr