2012-05-10 84 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