Javascript 如何在Dojo中更改ObjectStoreModel的默认值?
我正在使用DojoJavascript 如何在Dojo中更改ObjectStoreModel的默认值?,javascript,dojo,Javascript,Dojo,我正在使用DojoObjectStoreModel作为dijit/Tree小部件。 我需要配置ObjectStoreModel以使用名为parent\u id的属性,而不是默认的parent,以匹配我的数据结构 知道如何设置此配置吗 var data = [ { id: 'world', name: 'The earth', type: 'planet', population: '6 billion'
ObjectStoreModel
作为dijit/Tree小部件。
我需要配置ObjectStoreModel
以使用名为parent\u id
的属性,而不是默认的parent
,以匹配我的数据结构
知道如何设置此配置吗
var data = [
{
id: 'world',
name: 'The earth',
type: 'planet',
population: '6 billion'
},
{
id: 'EG',
name: 'Egypt',
type: 'country',
parent_id: 'AF' // does not work if property is called parent_id, only parent by default
},
{
id: 'Nairobi',
name: 'Nairobi',
type: 'city',
parent_id: 'KE'
},
{
id: 'Mombasa',
name: 'Mombasa',
type: 'city',
parent_id: 'KE'
},
{
id: 'SD',
name: 'Sudan',
type: 'country',
parent_id: 'AF'
},
];
var myStore = new Memory({
data: data,
getChildren: function (object) {
return this.query({ parent: object.id });
}
});
// Create the model
var myModel = new ObjectStoreModel({
store: myStore,
query: { id: '0' }
});
// Create the Tree.
var tree = new Tree({
model: myModel
});
tree.placeAt(this.domNode);
tree.startup();
我找到了解决我问题的办法 声明:
dojo.store必须实现自己的getChildren()方法。
因此,使用此编辑脚本可以很好地工作
var myStore = new Memory({
data: data,
getChildren: function (object) {
return this.query({ parent_id: object.id });
}
});