【问题标题】:How can we send field in Delete Action which are not Key我们如何在删除操作中发送不是键的字段
【发布时间】:2015-06-03 10:18:41
【问题描述】:

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

【问题讨论】:

  • 你能分享你正在处理的代码和你遇到的具体问题吗?

标签: ajax jquery-jtable


【解决方案1】:

我找到了答案。我们需要在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;
        }
    },
}

【讨论】:

    【解决方案2】:

    您可以编写自定义函数来删除,而不仅仅是 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');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      • 2023-02-06
      • 2019-08-04
      相关资源
      最近更新 更多