0

我想使用一个内存存储来驱动更多带有 dojo 和 dijit 的树视图。我正在使用 Observable 在将项目添加到continentStore 时更新树。但只有一棵树被更新。如何解决?

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();
4

1 回答 1

0

您应该使用同一家商店,因为每家商店都不知道另一家商店的情况。

取而代之的是:

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

用这个:

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

您可以删除otherStore

于 2013-06-07T12:12:09.473 回答