Charles
Charles

Reputation: 11758

extjs refresh tree store

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 ?

Upvotes: 2

Views: 7070

Answers (1)

Zero Cool
Zero Cool

Reputation: 1936

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

Upvotes: 1

Related Questions