2012-05-10 82 views
2

如何刷新樹存儲?extjs刷新樹存儲

我試圖做這樣的:

Ext.getStore('myStore').setRootNode({child: []}); 

然後商店將要求服務器有孩子,但有時它給了我一個孩子的兩倍。 在我的樹,我得到這樣的:

child1 
child2 
child1 

而且也有一個JavaScript錯誤:

Uncaught TypeError: Cannot read property 'internalId' of undefined 
Ext.define.updateIndexes ext-all-debug.js:61588 
Ext.define.onAdd ext-all-debug.js:61513 
Base.implement.callParent ext-all-debug.js:3728 

它是一個錯誤還是我做錯了什麼?

回答

1

我不知道你用的是什麼版本的ExtJS的,但這裏是我使用load方法如何刷新我的商店在4.1(你可能會或可能不會有參數的,我有一個):

this.getStore('MyTreeStore').load({ params: { id: this.getId().getValue()} }); 

商店用新記錄刷新,沒有任何以前的負載重複。

我有我的商店設置像這樣:

Ext.define('MyApp.store.MyTreeStore', { 
    extend: 'Ext.data.TreeStore', 
    model: 'MyApp.model.MyTreeModel', 

    root: { 
      children: [] 
    }, 

    proxy: { 
     type: 'ajax', 
     url: '/MyApp/Chart/GetTree' 
    }, 
    fields: [ 
     { name: 'id', type: 'int' } 
    ] 
}); 

和我的樹是這個樣子:

Ext.define('MyApp.view.chart.MyTree', { 
    extend: 'Ext.tree.Panel', 
    alias: 'widget.mytree', 

    id: 'MyTree', 
    store: 'MyTreeStore', 
    width: 350, 
    height: 320, 
    border: false, 
    rootVisible: false, 
    singleExpand: true 
}); 
+0

是我使用的是4.1,我會嘗試一下,謝謝。 – Charles

+0

謝謝我解決了這個問題,我在做兩次非常封閉的時間刷新。這就是爲什麼我有一些雙打。 – Charles