2
我使用Kendo UI Grid來顯示具有缺少某些字段的對象的數組數據。這裏是js代碼:Kendo UI Grid處理列模板中的缺失值
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>'
}]
});
它顯示在控制檯一個錯誤:沒有定義:未捕獲的ReferenceError。 即使更換模板:
template: '<b>#=a || ""#</b>'
表達,而不是沒有幫助,所以我必須構建表之前,需要手動設置爲空字符串的缺失值。有沒有辦法避免這種情況?
謝謝你的工作! – Aeteros