如何配置 dgrid 和它的存储来定义在呈现行时是否已经选择了行?
例如,如果我的行数据是这样的:
{
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();
});
}
);