如何配置dgrid及其存儲以定義在渲染行時是否已選擇一行?Dojo dgrid:(Pre)在渲染上選擇行
例如,如果我的行數據是像這樣:
{
id: 1,
name: 'Item Name',
selected: true
}
我當前的代碼是遍歷集合店內的被填充後,但我敢肯定,必須有一個更有效的方法做這個。
var items = [
{id: 1, name: 'Item 1', selected: true},
{id: 2, name: 'Item 2', selected: false}
];
require(
[
"dgrid/OnDemandGrid",
"dgrid/Selection",
"dojo/store/Memory",
"dojo/_base/declare",
"dojo/_base/array"
],
function (OnDemandGrid, Selection, Memory, declare, array) {
var store = new Memory({
data: items,
idProperty: "id"
});
var grid = new declare([OnDemandGrid, Selection])({
selectionMode: "multiple",
columns: {
id: { label: "ID" },
name: { label: "Name" }
},
store: store
}, "MyGrid");
array.forEach(items, function (item) {
if (item.selected) {
grid.select(grid.row(item.id));
}
});
grid.startup();
});
}
);
這樣做。值得注意的是,對於其他人,如果他們使用dgrid /選擇器,則應該將** get **方法添加到選擇器對象中,而不是常規列,因爲即使選中該行,checkbox/radio也不會被檢查。 – Buta