我们如何在删除操作中发送不是键的字段

How can we send field in Delete Action which are not Key

我需要在删除操作中发送未标记为键的字段。在我的案例中,我想使用多个字段删除一行。

您可以编写用于删除的自定义函数,而不仅仅是 URL。在这样做的同时,添加要发送的字段,以通过 ajax 发送数据。请参阅下面的代码以及文档 http://www.jtable.org/demo/FunctionsAsActions .

$('#Container').jtable({
        //...other code
        actions: {
            deleteAction: function (postData) {
                    console.log("deleting from custom function...");
                    //Attach your values to postData... 
                    //make sure you collect it in controller/code
                    postData.customData = $('#myinput').val();
                    return $.Deferred(function ($dfd) {
                        $.ajax({
                            url: '/Demo/DeleteStudent',
                            type: 'POST',
                            dataType: 'json',
                            data: postData,
                            success: function (data) {
                                $dfd.resolve(data);
                            },
                            error: function () {
                                $dfd.reject();
                            }
                        });
                    });
                },
            //...other actions
        },
    });

    //Load student list from server
    $('#Container').jtable('load');
});

我找到了答案。我们需要在 jtable

的字段部分添加此代码
customDelete: {
    title: '',
    width: '0.3%',
    display: function(data) {
    var $but = $('<button title="delete" class="jtable-command-button jtable-delete-command-button" >delete</button>');
               $but.click(function(){
                   var $dfd = $.Deferred();
                   if(data.record.configType == 'global')
                   {
                       alert('Global Type Configuration are not allowed for deletion.')
                       return false;
                   }
                   if (confirm('Are you sure you want to delete this?')) {
                         $.ajax({
                            url: '/admin/configuration/delete',
                            type: 'POST',
                            dataType: 'json',
                            data: data.record,
                            success: function (data) {
                                $dfd.resolve(data);
                                $('#Container').jtable('load') ;

                            },
                            error: function () {
                                $dfd.reject();
                            }
                        });
                }
            });
            return $but;
        }
    },
}