【发布时间】:2015-06-03 10:18:41
【问题描述】:
我需要在删除操作中发送未标记为键的字段。在我的案例中,我想使用多个字段删除一行。
【问题讨论】:
-
你能分享你正在处理的代码和你遇到的具体问题吗?
标签: ajax jquery-jtable
我需要在删除操作中发送未标记为键的字段。在我的案例中,我想使用多个字段删除一行。
【问题讨论】:
标签: ajax jquery-jtable
我找到了答案。我们需要在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;
}
},
}
【讨论】:
您可以编写自定义函数来删除,而不仅仅是 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');
});
【讨论】: