Javascript Kendo dataSource.add-“添加”;“未定义Id”;
我试图将一些项目添加到剑道数据源中,然后显示在网格中。但是,每次尝试保存时,都会出现Javascript Kendo dataSource.add-“添加”;“未定义Id”;,javascript,kendo-ui,kendo-grid,Javascript,Kendo Ui,Kendo Grid,我试图将一些项目添加到剑道数据源中,然后显示在网格中。但是,每次尝试保存时,都会出现引用错误:未定义Id 起初我认为这是因为我没有在我的模式中包含Id,但我检查了一下,结果看起来还不错 var viewModel = new kendo.observable({ orgDataSource: new kendo.data.DataSource({ transport: { read: { url: "/Organization/GetAll",
引用错误:未定义Id
起初我认为这是因为我没有在我的模式中包含Id
,但我检查了一下,结果看起来还不错
var viewModel = new kendo.observable({
orgDataSource: new kendo.data.DataSource({
transport: {
read: {
url: "/Organization/GetAll",
dataType: "json"
},
update: {
url: "/Host/Organization/Edit",
dataType: "json",
type: "POST",
data: {
__RequestVerificationToken: getAntiForgeryToken()
}
},
create: {
url: "/Host/Organization/Create",
dataType: "json",
type: "POST",
data: {
__RequestVerificationToken: getAntiForgeryToken()
}
},
destroy: {
url: "/Host/Organization/Delete",
dataType: "json",
type: "POST",
data: {
__RequestVerificationToken: getAntiForgeryToken()
}
}
},
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number", editable: false, nullable: true },
Name: { type: "string" },
LicenseExpiration: { type: "date" },
LicenseNumber: { type: "number" },
Active: { type: "boolean" },
CreateDate: { type: "date" },
LastModDate: { type: "date" },
AvailableLicenses: { type: "string" },
State: { type: "string" }
}
},
errors: "errorMsg"
},
pageSize: 20,
error: function (e) {
toastr.options = {
"positionClass": "toast-bottom-full-width"
};
toastr.error("There was an error: " + e.errors, "Uh, Oh!");
this.cancelChanges();
},
serverPaging: false,
serverFiltering: false,
serverSorting: false
}),
reloadOrganizations: function () {
this.get("orgDataSource").read();
},
onOrgSave: function (e)
{
var uid = $('input[name="OrgRowUID"]').val();
var tr = $('tr[data-uid="' + uid + '"]'); // get the current table row (tr)
var name = $('input[name="Name"]').val();
var licenseNumber = $('input[name="LicenseNumber"]').val();
var licenseExpiration = $('input[name="LicenseExpiration"]').val();
var email = $('input[name="Email"]').val();
var state = $('input[name="State"]').val();
var logo = $('input[name="ImageUrl]').val();
var active = $('input[name="Active"]').is(":checked");
// get the data bound to the current table row
var orgGrid = $("#OrganizationGrid").data("kendoGrid");
var data = orgGrid.dataItem(tr);
if (data == null)
{
viewModel.orgDataSource.add({ Name: name, LicenseNumber: licenseNumber, LicenseExpiration: licenseExpiration, Email: email, State: state, ImageUrl: logo, Active: active })
orgGrid.saveChanges();
viewModel.orgDataSource.sync();
viewModel.reloadOrganizations();
} else {
data.set("Name", name);
data.set("LicenseNumber", licenseNumber);
data.set("LicenseExpiration", licenseExpiration);
data.set("Email", email);
data.set("State", state);
data.set("ImageUrl", logo);
data.set("Active", active);
}
$("#orgCreateModal").modal('hide');
$("#orgEditModal").modal('hide');
}
});
此行出现错误:
viewModel.orgDataSource.add({ Name: name, LicenseNumber: licenseNumber, LicenseExpiration: licenseExpiration, Email: email, State: state, ImageUrl: logo, Active: active });
FireBug中的错误是:
参考错误:未定义Id-kendo.all.min.js第25行>函数
它抛出这个错误是因为您没有为数据源中的任何内容设置“Id”。不久前我也遇到过类似的问题,Telerik说你必须给“id”一个有效的唯一值,因为他们在内部使用这个值来保持数据源中的事情的正确性。在本例中,您将模式id设置为“id”,但数据源似乎没有“id”字段。我最后只是在那里转储了一个guid,它解决了我的问题。谢谢@Ageonix,这是有道理的。我试试看会发生什么。你运气好吗?