我使用KnockOut可觀察數組來填充wijgrid。在wijgrid中,我想使用JavaScript對象作爲某些單元格的值。不幸的是,似乎wijmo將對象轉換爲它自己模型中的字符串。是否有可能在wijgrid中有對象類型的單元格?
請有一個look at this example。我想在表格中顯示車主名稱,但我還需要保留id(和模型數據結構)。
淘汰賽視圖模型
var someData =[ { AssetCode: "Truck 5",
Owner: {
id: 1,
name: 'Pete'},
VIN: "T3SN2ADN",
Odo:9,
TimeStamp: "2012-07-21T09:13:12Z"},
{ AssetCode: "Car 8",
Owner: {
id: 3,
name: 'Brian'},
VIN: "COFAQ211",
Odo: 433299,
TimeStamp: "2012-07-17T15:34:54Z"}];
function ViewModel() {
var self = this;
self.gridData = ko.observableArray(someData);
}
ko.applyBindings(new ViewModel());
的wijgrid
<table id="t1" data-bind="wijgrid: {
data: gridData,
columns: [
{ headerText: 'Asset Code', dataKey: 'AssetCode', dataType: 'string'},
{ headerText: 'Owner name', dataKey: 'Owner'}, <!-- PROBLEM LINE -->
{ headerText: 'VIN', dataKey: 'VIN', dataType: 'string' },
{ headerText: 'Odometer', dateKey: 'Odo', dataType: 'number' },
{ headerText: 'Time', dataKey: 'TimeStamp', dataType: 'datetime', dataFormatString: timePattern }
]}"></table>
我已經試過:
- 標準的淘汰賽方式:
{ headerText: 'Owner name', dataKey: 'Owner.name'}
- 創建自定義cellFormatter:
{ headerText: 'Owner name', dataKey: 'Owner', cellFormatter: MY_FORMATTER}
我已經試過幾乎所有我能想到的得到這個工作,但似乎wijmo這裏非常剛性....
此外,當我調試在Chrome中,似乎wijmo已經在格式化之前將對象轉換爲自己模型中的字符串。這不是非常有用..
編輯 - 我們正在使用Wijmo 2.3.9。我們在Wijmo 3上遇到了性能問題。*到目前爲止,升級並不是迫在眉睫。
不幸的是,'cellStyleFormatter'從相同的問題'cellFormatter'受到影響。 'args.row.data.Owner'的值是:「[object Object]」。即它是一個字符串不是所有者對象。這對我不起作用。 :( – Muel 2013-05-03 00:31:16
雖然我忘了說謝謝你的答案,如果你有其他想法,我很樂意嘗試一下! – Muel 2013-05-03 00:31:59