我正在尝试向我的网格的删除按钮添加一些验证,因此我让删除按钮在单击时执行一个功能,但它似乎忽略了该功能。这是功能:
function locDelete(e) {
var len = this.dataSource.data().length;
var item = $("#trespassed-location-list").data("kendoGrid").dataItem($(this).closest("tr"));
if (len === 1) {
alert("There must be at least one location.");
}
else {
alert("This is in the else");
//this.remove(item);
//this.removeRow($(e.target).closest("tr"));
}
}
我把第二个警报放在那里进行测试,没有一个警报被击中。这是网格代码和数据源:
var PersId = $("#PersonId").val();
var ds_locationsList = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("JsonPopulateTrespassList", "TrespassOrder")/' + PersId,
dataType: 'json',
type: "POST"
},
destroy: {
url: '@Url.Action("JsonDeleteLocation", "TrespassOrder")',
dataType: 'json',
type: "POST"
}
},
parameterMap: function (options, operation) {
if (operation == "destroy" && options.models) {
var values = {};
values["TrespassLocId"] = options.models[0].TrespassLocId;
return values;
}
},
schema: {
model: {
id: "TrespassedLocId",
fields: {
TrespassLocId: { editable: false},
LocationName: { editable: false }
}
}
},
pageSize: 20
});
$(document).ready(function () {
$("#trespassed-location-list").kendoGrid({
dataSource: ds_locationsList,
sortable: true,
height: "150px",
width: "300px",
editable: "inline",
columns: [{
field: "LocationName", title: "Trespassed Location(s)"
}, {
command: [{ name: "destroy", text: "Delete", click: locDelete }],
width: "110px",
}]
});
如果我注释掉 LocDelete 函数,我会收到一个“locDelete undefined”错误,所以我知道网格正在寻找它。删除确认通知会搞砸吗?但是使用上面编写的 locDelete 函数(注释掉删除代码后,该行仍然会从数据库库和客户端中删除。我尝试使用 firebug 跟踪它,但我的断点永远不会被 locDelete 函数命中。