【发布时间】:2015-06-23 05:26:34
【问题描述】:
我使用 Kendo UI Grid 来显示缺少某些字段的对象的数组数据。这是js代码:
var arr = [{b: "b1"}, {a: "a2", b: "b2"}];
$("#grid").kendoGrid({
dataSource: arr,
columns: [
{
title: "The A column",
field: 'a'
}, {
title: "The B column",
template: '<i>#=b#</i>'
}]
});
在本例中,网格运行良好,第一行中缺少的“a”值显示为空单元格。
使用列模板时:
$("#grid").kendoGrid({
dataSource: arr,
columns: [
{
title: "The A column",
template: '<b>#=a#</b>'
}, {
title: "The B column",
template: '<i>#=b#</i>'
}]
});
它在控制台中显示一个错误:Uncaught ReferenceError: a is not defined。 甚至将模板替换为:
template: '<b>#=a || ""#</b>'
表达式反而没有帮助,所以我必须在构造表之前手动将缺失值设置为空字符串。有没有办法避免这种情况?
【问题讨论】:
标签: javascript kendo-ui kendo-grid kendo-template