一个dojo / store / Memory上的更多dijit / Tree实例

时间:2013-05-31 16:47:38

标签: tree dojo

我想使用一个Memory存储来使用dojo和dijit来驱动更多树视图。 当一个项目被添加到continentStore时,我正在使用Observable来更新树。 但只有一棵树被更新。 怎么解决?

continentStore = new Memory({
data: [

        { id: 'world', name:'The earth', type:'planet', population: '6 billion'},
        { id: 'AF', name:'Africa', type:'continent', population:'900 million', area: '30,221,532 sq km',
                timezone: '-1 UTC to +4 UTC', ancestor: 'world'},
            { id: 'EG', name:'Egypt', type:'country', ancestor: 'AF', parent: 'world' },
            { id: 'KE', name:'Kenya', type:'country', ancestor: 'AF', parent: 'EG' },
                { id: 'Nairobi', name:'Nairobi', type:'city', ancestor: 'KE' },
                { id: 'Mombasa', name:'Mombasa', type:'city', ancestor: 'KE' },
            { id: 'SD', name:'Sudan', type:'country', ancestor: 'AF' },
                { id: 'Khartoum', name:'Khartoum', type:'city', ancestor: 'SD' },
        { id: 'AS', name:'Asia', type:'continent', ancestor: 'world' },
            { id: 'CN', name:'China', type:'country', ancestor: 'AS' },
            { id: 'IN', name:'India', type:'country', ancestor: 'AS' },
            { id: 'RU', name:'Russia', type:'country', ancestor: 'AS' },
            { id: 'MN', name:'Mongolia', type:'country', ancestor: 'AS' },
        { id: 'OC', name:'Oceania', type:'continent', population:'21 million', ancestor: 'world'},
        { id: 'EU', name:'Europe', type:'continent', ancestor: 'world' },
            { id: 'DE', name:'Germany', type:'country', ancestor: 'EU' },
            { id: 'FR', name:'France', type:'country', ancestor: 'EU' },
            { id: 'ES', name:'Spain', type:'country', ancestor: 'EU' },
            { id: 'IT', name:'Italy', type:'country', ancestor: 'EU' },
        { id: 'NA', name:'North America', type:'continent', ancestor: 'world' },
        { id: 'SA', name:'South America', type:'continent', ancestor: 'world' }
] ,
getChildren: function(object) {
   return this.query({parent: object.id});
   },
getSuccessor: function(object) {
   return this.query({ancestor: object.id});
   }
});

continentStore = new Observable(continentStore);

otherStore = new Observable(continentStore);
otherStore.getChildren = otherStore.getSuccessor;
// Create the model
var continentModel = new ObjectStoreModel({ store: continentStore, query: {id: 'world'}});
var tree = new Tree({ model: continentModel });
//alert(dom.byId("Tree1"))
tree.placeAt(dom.byId("Tree1"));
tree.startup();

// Create the model
var continentModel2 = new ObjectStoreModel({ store: otherStore, query: {id: 'world'} });
var tree2 = new Tree({ model: continentModel2 });
//alert(dom.byId("Tree1"))
tree2.placeAt(dom.byId("Tree2"));
tree2.startup();

1 个答案:

答案 0 :(得分:0)

您应该使用同一商店,因​​为每家商店都不了解其他商店。

取而代之的是:

var continentModel2 = new ObjectStoreModel({ 
    store: otherStore, query: {id: 'world'} });

使用它:

var continentModel2 = new ObjectStoreModel({ 
    store: continentStore, query: {id: 'world'} });

您可以删除otherStore