2013-05-31 36 views
0

我想用一個內存商店驅動更多的樹視圖與dojo和dijit。 我正在使用Observable將項目添加到continentStore時更新樹。 但只有其中一棵樹被更新。 如何解決?更多dijit /樹實例在一個dojo /商店/內存

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(); 
+0

你可能想改變這種continentStore =新的觀察,(continentStore),因爲你現在改寫你用可存儲的存儲記憶,然後用它來存儲其他商店。 – Marius

回答

0

您應該使用相同的商店,因爲每個商店都不知道其他商店的相關信息。

而是這樣的:

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

使用本:

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

您可以刪除otherStore