kendo-ui 中的下拉菜单未检索数据
Drop-down in kendo-ui not retrieving data
我正在做测试项目,我从网络上填写下拉列表 api...
按原样使用 ThisDemo....
有一次一切正常,现在它一直显示控制台错误,我在问题末尾已经说过...
我确定只有目标模板有问题
{template: "#=Status.StatusName#"}
...我不确定这是否正确...但是当我删除此代码时部分错误消失但下拉列表显示未定义而不是 StatusName...
查看代码(我已经使用了选择的脚本)
...
schema: {
model: {
id: "ProjectId",
fields: {
ProjectId: { editable: true, nullable: false, type: "number" },
ClientId: { editable: true, nullable: false, type: "number" },
Name: { editable: true, nullable: true, type: "string" },
// Status: { editable: true, nullable: true, type: "string" },
Status: { defaultValue: { StatusID: 1, StatusName: "Completed" } },
IsActive: { editable: true, nullable: false, type: "boolean" },
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
toolbar: ["create"],
scrollable: false,
sortable: true,
groupable: true,
filterable: true,
columns: [
{ field: "Name", title: "Project Name", width: "170px" },
//{ field: "Status", title: "Status", width: "110px" },
{ field: "Status", title: "Status", width: "180px", editor: statusDropDownEditor, template: "#=Status.StatusName#" },
{ field: "IsActive", title: "Active", width: "50px" },
{ command: "", template: "<a href='Project/Task'>Manage Task</a>", width: "30px", filterable: false },
{ command: "", template: "<a href='Project/Setting'>Setting</a>", width: "30px", filterable: false },
{ command: ["edit", "delete"], title: " ", width: "80px" }
],
editable: "popup"
});
function statusDropDownEditor(container, options) {
$('<input required data-text-field="StatusName" data-value-field="StatusID" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: {
type: "odata",
transport: {
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Categories"
}
}
});
}
Uncaught TypeError: Cannot read property 'StatusName' of
null(anonymous function) @
VM1415:1pt.ui.DataBoundWidget.extend._rowsHtml @
kendo.all.min.js:31pt.ui.DataBoundWidget.extend._renderContent @
kendo.all.min.js:32pt.ui.DataBoundWidget.extend.refresh @
kendo.all.min.js:32b.extend.proxy.b.isFunction.i @
jquery.min.js:3i.extend.trigger @ kendo.all.min.js:9ht.extend._process
@ kendo.all.min.js:11ht.extend.success @
kendo.all.min.js:11ht.extend.read.n._queueRequest.n.online.n.transport.read.success
@ kendo.all.min.js:11pt.extend.read.n.success @
kendo.all.min.js:11b.Callbacks.c @
jquery.min.js:3b.Callbacks.p.fireWith @ jquery.min.js:3k @
jquery.min.js:5b.ajaxTransport.send.r @ jquery.min.js:5
如果有人有任何想法,请提供帮助,我们将不胜感激感谢您的宝贵时间
问题与 odata 服务返回的数据有关。数据如下所示:
ProductID : 1,
ProductName : "Chai",
SupplierID : 1,
CategoryID : 1,
QuantityPerUnit : "10 boxes x 20 bags",
UnitPrice : 18.0000,
UnitsInStock : 39,
UnitsOnOrder : 0,
ReorderLevel : 10,
Discontinued : false,
Category : {
CategoryID : 1,
CategoryName : "Beverages",
Description : "Soft drinks, coffees, teas, beers, and ales"
}
如您所见,odata 服务返回的数据中没有Status
。缺少的字段(如 Status
)将被解析为 undefined
值。但是,如果您尝试获取该 undefined
对象的 属性(就像您的模板所做的那样),您最终会遇到错误,因为您无法执行 undefined.undefined
.
作为旁注; defaultValue
不受 kendo model 支持。
我正在做测试项目,我从网络上填写下拉列表 api... 按原样使用 ThisDemo....
有一次一切正常,现在它一直显示控制台错误,我在问题末尾已经说过...
我确定只有目标模板有问题
{template: "#=Status.StatusName#"}
...我不确定这是否正确...但是当我删除此代码时部分错误消失但下拉列表显示未定义而不是 StatusName...
查看代码(我已经使用了选择的脚本)
...
schema: {
model: {
id: "ProjectId",
fields: {
ProjectId: { editable: true, nullable: false, type: "number" },
ClientId: { editable: true, nullable: false, type: "number" },
Name: { editable: true, nullable: true, type: "string" },
// Status: { editable: true, nullable: true, type: "string" },
Status: { defaultValue: { StatusID: 1, StatusName: "Completed" } },
IsActive: { editable: true, nullable: false, type: "boolean" },
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
toolbar: ["create"],
scrollable: false,
sortable: true,
groupable: true,
filterable: true,
columns: [
{ field: "Name", title: "Project Name", width: "170px" },
//{ field: "Status", title: "Status", width: "110px" },
{ field: "Status", title: "Status", width: "180px", editor: statusDropDownEditor, template: "#=Status.StatusName#" },
{ field: "IsActive", title: "Active", width: "50px" },
{ command: "", template: "<a href='Project/Task'>Manage Task</a>", width: "30px", filterable: false },
{ command: "", template: "<a href='Project/Setting'>Setting</a>", width: "30px", filterable: false },
{ command: ["edit", "delete"], title: " ", width: "80px" }
],
editable: "popup"
});
function statusDropDownEditor(container, options) {
$('<input required data-text-field="StatusName" data-value-field="StatusID" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: {
type: "odata",
transport: {
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Categories"
}
}
});
}
Uncaught TypeError: Cannot read property 'StatusName' of null(anonymous function) @ VM1415:1pt.ui.DataBoundWidget.extend._rowsHtml @ kendo.all.min.js:31pt.ui.DataBoundWidget.extend._renderContent @ kendo.all.min.js:32pt.ui.DataBoundWidget.extend.refresh @ kendo.all.min.js:32b.extend.proxy.b.isFunction.i @ jquery.min.js:3i.extend.trigger @ kendo.all.min.js:9ht.extend._process @ kendo.all.min.js:11ht.extend.success @ kendo.all.min.js:11ht.extend.read.n._queueRequest.n.online.n.transport.read.success @ kendo.all.min.js:11pt.extend.read.n.success @ kendo.all.min.js:11b.Callbacks.c @ jquery.min.js:3b.Callbacks.p.fireWith @ jquery.min.js:3k @ jquery.min.js:5b.ajaxTransport.send.r @ jquery.min.js:5
如果有人有任何想法,请提供帮助,我们将不胜感激感谢您的宝贵时间
问题与 odata 服务返回的数据有关。数据如下所示:
ProductID : 1,
ProductName : "Chai",
SupplierID : 1,
CategoryID : 1,
QuantityPerUnit : "10 boxes x 20 bags",
UnitPrice : 18.0000,
UnitsInStock : 39,
UnitsOnOrder : 0,
ReorderLevel : 10,
Discontinued : false,
Category : {
CategoryID : 1,
CategoryName : "Beverages",
Description : "Soft drinks, coffees, teas, beers, and ales"
}
如您所见,odata 服务返回的数据中没有Status
。缺少的字段(如 Status
)将被解析为 undefined
值。但是,如果您尝试获取该 undefined
对象的 属性(就像您的模板所做的那样),您最终会遇到错误,因为您无法执行 undefined.undefined
.
作为旁注; defaultValue
不受 kendo model 支持。