PDA

View Full Version : TreeStore Loading Twice



jeromer
10 Jan 2012, 11:52 AM
The answer will probably shame me, but here is the question. I have a treepanel that I load via autoload: true or autoload:false and I via program code do the load of the store. When I use the autoload:true option, the tree loads once. When I load via load statement, I get double the nodes. I've attached a load listener and it fires twice when I load via code. What is causing this and what can I do to stop it?



/*
* File: designer.js
* Date: Wed Jan 04 2012 15:43:19 GMT-0800 (Pacific Standard Time)
*
* This file was generated by Ext Designer version 1.2.2.
* http://www.sencha.com/products/designer/
*
* This file will be auto-generated each and everytime you export.
*
* Do NOT hand edit this file.
*/

Ext.Loader.setConfig({
enabled: true
});

Ext.application({
name: 'PSS',
appFolder: 'app',
controllers: ['topTabController'],
views:['MyViewport','topTabs','projTreeView'],
models:['projTreeModel'],
launch: function() {

Ext.QuickTips.init();

Ext.define('projTreeModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'text', type:'string'},
{name: 'description', type:'string'}
]
// ,
// {name: 'expanded', type: 'boolean'},
// {name: 'leaf', type: 'boolean'},
// {name: 'children', type: 'boolean'}
// ]
}
);

var loaded = false;


projStore = Ext.create('Ext.data.TreeStore',{
model: 'projTreeModel',
storeId: 'projStore',
autoLoad: true,
proxy: {
type:'ajax',
url:'app/data/proj.json',
reader:
{
type:'json'
//,root:'MyProjects'
}


}
// ,root : {
// text : 'MyProjects',
// id : 'MyProjects',
// expanded : true
// }

});



var cmp1 = Ext.create('PSS.view.MyViewport', {
renderTo: Ext.getBody()
});

projStore.on('load',function(treestore, node, recs, stat, eopts) {console.log('doing it'};);



//projStore.load();


cmp1.show();

}
});

renato01
11 Jan 2012, 5:36 AM
Sounds very familiar!
Not so sure anymore how I fixed it.
But I believe it had something to do with the root node trying to get its children..

If I look back at my code, I have this in my treeStore:
Try defining a rootNode, with empty children array..



autoLoad: false,
root:{
"Text": "TreeRootNode",
"expanded": false,
"children": []
}

jeromer
11 Jan 2012, 9:07 AM
Works. Thanks. Glad it works, but feel a little helpless cause I don't really know why.


Maybe someone will jump in and explain the logic of or triggers that causes the proxy to request more data reads.