我使用 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>'
相反,表达式没有帮助,因此我必须在构建表之前手动将缺失值设置为空字符串。有没有办法避免这种情况?