这是一个缺陷,但事实并非如此。您的 JSON 结构并不完全正确,因为任何值都不允许作为数组,除非它是 childAttrs 之一。由于 [1,2,3].toString() 的性质,这就是您尝试将值设置为数组的原因。
ItemFileReadStore 中的 get/set 与它的项目一起工作:
store._arrayOfAllItems = {
value1 : { values : [ 'realvalue' ] },
value2 : { values : [ 'realvalue' ] }
};
getter 然后说
store.get = function(itemById, val) { return itemById[val][0]; }
// why only the first arrayslot is pulled from store---/^
在您的 JSON 构造中,是什么禁止您设置如下值?
var data = {
id: 'id',
label: 'id',
items: [
{
id: "value1",
values: "a,b,c" // permit-able string value
},
{
id: "value2",
values: "foo"}
]
};
如果您想要一个 ID 的同一个键的多个值,那么您必须将数据作为子级传递并按原样处理它们,例如;
data: {
id: 'id',
label: 'id',
childrenAttrs: [ 'items', 'children'], // << default behavior
items: [ {
id: "value1",
children: [
{ id: "value1_1", values: 'a' },
{ id: "value1_2", values: 'b' },
{ id: "value1_3", values: 'c' }
]
}, {
id: "value2",
values: "foo"
} ]
}
但是,只有 dojox.grid.TreeGrid 允许使用多级数据存储