PDA

View Full Version : Load data for TreePanel twice



DmitryF
9 Jul 2012, 9:11 AM
Hello.

I have a TreePanel with TreeStore.
When i activate my TreePanel the store loads. It works fine.

But if i load the data twice (i send the second ajax request before the first ajax request complete), i have an error:
records[I] is undefined

For example:


Ext.define('MyApp.store.MyTree', {
extend: 'Ext.data.TreeStore',
fields: [
'id', 'title'
],
proxy: {
type: 'ajax',
method: 'POST',
url: '/module/action',
reader: {
type: 'json',
successProperty: 'success',
idProperty: 'id'
}
}
});

Ext.define('MyApp.view.TreePanel' ,{
extend: 'Ext.tree.Panel',
store: 'MyTree',
rootVisible: false,
columns: [{
xtype: 'treecolumn',
text: 'Title',
dataIndex: 'title'
}]
}

Ext.getStore('MyTree').load(); //first request
Ext.getStore('MyTree').load(); //second request

sword-it
9 Jul 2012, 10:34 PM
But if i load the data twice (i send the second ajax request before the first ajax request complete), i have an error:
[I]records is undefined



Hi!

i am wondering why are you sending second request before completion of first one.

BTW, i guess the problem is with same 'id' for each data set or nodes with same id across various branches during ajax requests

if you still need second request before completion of first, then try to generate json node items with unique id's.

DmitryF
9 Jul 2012, 11:30 PM
I have the function for card layout:


activateItemWithTree: function() {
Ext.getStore('MyTree').load();
}


If i quickly switch the items of the card panel, i get the error.

This is my JSON:


{
"success": true,
"text": ".",
"children": [{
"id":"2", "title":"item1"
}]}

Id's from the database. Do I need to generate other id's based on current time()...?

redraid
10 Jul 2012, 3:07 AM
Create buffered function to load store:

var loadTree = Ext.Function.createBuffered(function () {Ext.getStore('MyTree').load();}, 100);

...

activateItemWithTree: function() {
loadTree();
}

DmitryF
11 Jul 2012, 12:12 AM
redraid, thank you for the advice, but it doesn't work :(

I found a solution:


if (!Ext.getStore('MyTree').isLoading())
Ext.getStore('MyTree').load();