创建带导航的网格模型 Kendo UI 问题 属性
Issue Creating Kendo UI Grid Model with Navigation Property
我正在使用 kendo ui 网格并尝试为我的模型添加 CRUD 操作,该模型具有一些导航属性。这是我的架构:
schema: {
data: function (data) {
return data || [];
},
model: {
id: "Id",
fields: {
Id: { editable: false,
nullable: false,
type: "number"
},
Frequency: { type: "string" },
FREQ_POOL: { type: "object" },//THIS IS A NAV IN MY MODEL
}
}
}
这是我的网格:
$("#AFTRCCFreqGrid").kendoGrid({
dataSource: AFTRCCDS,
columns: [
// { field: "Id", title: "Freq ID", format: "{0:c}", width: "120px" },
{ field: "Frequency", title: "Frequency", editor: categoryDropDownEditor, format: "{0:c}", width: "120px" },
{ field: "FREQ_POOL.Comments", title: "Comments", format: "{0:c}", width: "120px" },
{ command: ["edit", "destroy"], title: " ", width: "250px" }
],
toolbar: ["create"],
editable: "inline",
pageable: true
});
当我点击 kendo 网格中的 "Add New Record Button" 时,出现以下错误:
Uncaught TypeError: Cannot read property 'Comments' of undefined(anonymous function) @ VM2305:3kendo.ui.DataBoundWidget.extend._rowsHtml @ kendo.all.js:55504kendo.ui.DataBoundWidget.extend._renderContent @ kendo.all.js:56181kendo.ui.DataBoundWidget.extend.refresh @ kendo.all.js:56084jQuery.extend.proxy.proxy @ jquery.js:548Class.extend.trigger @ kendo.all.js:181Observable.extend._process @ kendo.all.js:8378Observable.extend._change @ kendo.all.js:8317jQuery.extend.proxy.proxy @ jquery.js:548Class.extend.trigger @ kendo.all.js:181Observable.extend.splice @ kendo.all.js:5371Observable.extend.insert @ kendo.all.js:7587kendo.ui.DataBoundWidget.extend.addRow @ kendo.all.js:53021(anonymous function) @ kendo.all.js:53086jQuery.event.dispatch @ jquery.js:4665jQuery.event.add.elemData.handle @ jquery.js:4333
事情是这样的。我手动向我的 SQL table 添加了一行,我可以使用 kendo 网格成功地 UPDATE 该行。我可以编辑导航属性 "Comments"。但出于某种原因,当我创建一个新行时,我无法让它工作。
我的猜测是,当我加载 table 时它会加载导航属性,但是当我点击 "Add New Record" 时,它不知道如何创建导航 属性 "From scratch",而当我更新一行时,它已经加载了导航 属性 信息。
有什么办法可以解决这个问题吗?谢谢。
编辑:
附带说明一下,我拥有的其他使用类似代码的网格没有此问题,但是当我向网格添加新行并且 post 时,导航属性为空。它们唯一不为空的时间是在我编辑时。创建新行时我应该如何 "initialize" 导航属性?
我认为在这种情况下您需要使用模板。对于评论字段,代码如下所示:
{
field: "Comments", template: function(dataItem) {
return dataItem.FREQ_POOL["Comments"];
}
}
我创建了一个jsbin to show how it fetches value from an object
希望对您有所帮助
我正在使用 kendo ui 网格并尝试为我的模型添加 CRUD 操作,该模型具有一些导航属性。这是我的架构:
schema: {
data: function (data) {
return data || [];
},
model: {
id: "Id",
fields: {
Id: { editable: false,
nullable: false,
type: "number"
},
Frequency: { type: "string" },
FREQ_POOL: { type: "object" },//THIS IS A NAV IN MY MODEL
}
}
}
这是我的网格:
$("#AFTRCCFreqGrid").kendoGrid({
dataSource: AFTRCCDS,
columns: [
// { field: "Id", title: "Freq ID", format: "{0:c}", width: "120px" },
{ field: "Frequency", title: "Frequency", editor: categoryDropDownEditor, format: "{0:c}", width: "120px" },
{ field: "FREQ_POOL.Comments", title: "Comments", format: "{0:c}", width: "120px" },
{ command: ["edit", "destroy"], title: " ", width: "250px" }
],
toolbar: ["create"],
editable: "inline",
pageable: true
});
当我点击 kendo 网格中的 "Add New Record Button" 时,出现以下错误:
Uncaught TypeError: Cannot read property 'Comments' of undefined(anonymous function) @ VM2305:3kendo.ui.DataBoundWidget.extend._rowsHtml @ kendo.all.js:55504kendo.ui.DataBoundWidget.extend._renderContent @ kendo.all.js:56181kendo.ui.DataBoundWidget.extend.refresh @ kendo.all.js:56084jQuery.extend.proxy.proxy @ jquery.js:548Class.extend.trigger @ kendo.all.js:181Observable.extend._process @ kendo.all.js:8378Observable.extend._change @ kendo.all.js:8317jQuery.extend.proxy.proxy @ jquery.js:548Class.extend.trigger @ kendo.all.js:181Observable.extend.splice @ kendo.all.js:5371Observable.extend.insert @ kendo.all.js:7587kendo.ui.DataBoundWidget.extend.addRow @ kendo.all.js:53021(anonymous function) @ kendo.all.js:53086jQuery.event.dispatch @ jquery.js:4665jQuery.event.add.elemData.handle @ jquery.js:4333
事情是这样的。我手动向我的 SQL table 添加了一行,我可以使用 kendo 网格成功地 UPDATE 该行。我可以编辑导航属性 "Comments"。但出于某种原因,当我创建一个新行时,我无法让它工作。
我的猜测是,当我加载 table 时它会加载导航属性,但是当我点击 "Add New Record" 时,它不知道如何创建导航 属性 "From scratch",而当我更新一行时,它已经加载了导航 属性 信息。
有什么办法可以解决这个问题吗?谢谢。
编辑:
附带说明一下,我拥有的其他使用类似代码的网格没有此问题,但是当我向网格添加新行并且 post 时,导航属性为空。它们唯一不为空的时间是在我编辑时。创建新行时我应该如何 "initialize" 导航属性?
我认为在这种情况下您需要使用模板。对于评论字段,代码如下所示:
{
field: "Comments", template: function(dataItem) {
return dataItem.FREQ_POOL["Comments"];
}
}
我创建了一个jsbin to show how it fetches value from an object
希望对您有所帮助