extjs refresh tree store

允我心安 提交于 2020-01-04 08:59:17

问题


how to refresh a Tree Store ?

I tried to do like that:

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

And then the Store will request the Server to have children but sometimes it gives me a child in double. In my Tree I get something like:

child1
child2
child1

and there is also a javascript error:

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

Is it a bug or am I doing something wrong ?


回答1:


I'm not sure what version of extjs you're using but here's how I refresh my store in 4.1 using the load method (you may or may not have parameters, I have one):

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

The store is refreshed with new records with no duplicates from any previous load.

I have my store setup like so:

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' }
    ]
});

and my Tree looks like this:

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
});


来源:https://stackoverflow.com/questions/10539662/extjs-refresh-tree-store

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!