PDA

View Full Version : TreeStore loading on demand



frankbolviken
21 Sep 2011, 4:49 AM
Hi,

I have a tree, which I wan't to be able to lazy load. When a user clicks the expand button, a request should be made. And the data should be added to the tree as a subfolder. It current works now, if you start from scratch.
But lets say a user navigates in trough a history url (#siteName/documentLibrary/). The first level is loaded correctly. (siteName). A new request is automatically made with the #siteName/documentLibrary" as path, which should load the 2 subfolders this folder has. The server returns the correct amount of folders, but for some reason, they are added twice to the tree. Which corrups the tree, and making it do all sort of strange things. See image below.

28203

There request has been made only once, so there seems to be no problems at serverside. So can anyone help with this issue? Sorry for a bad explanation :P

Frank

tvanzoelen
21 Sep 2011, 5:34 AM
I had this once .. but forgot what it was exactly. But, can you check if the id's of your nodes are unique in your tree. Every node should have a unique id. Else you get troubles...and I think this one.

Whats under node links? frank and test234 with the same ids as under documentLibrary?

One of the problem was you cannot expand odes anymore .. and probably double nodes.

frankbolviken
21 Sep 2011, 10:00 PM
ID is unique as I can see. But I get an exception now:

Uncaught TypeError: Cannot read property 'internalId' of undefined

tvanzoelen
21 Sep 2011, 11:05 PM
for that one you must post some code....

frankbolviken
21 Sep 2011, 11:37 PM
Thats just it, I don't know where to start :P

I can atleast provide som code about my models and stores.


Ext.define('app.store.DocumentLibraryNavigation', { extend: 'Ext.data.TreeStore',

model: 'app.model.Folder',
autoLoad: false,
proxy: {
requestMethod: 'GET',
type: 'ajax',
url: 'services/folder/childrenDynamic',
reader: {
type: 'json',
root: 'data'
}
},
root: {
text: 'root'
}
});





Ext.define('app.model.Folder', { extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string' },
'title',
'description',
'nodeType',
// { name: 'id', mapping: 'path'},
{ name: 'nodeRef', type: 'string'},
{ name: 'items', type: 'auto'},
{ name: 'path', type: 'string'},
{ name: 'cls', mapping: 'cls'},
'iconCls'
]
});

I've uncommented the ID part, because I'm setting it serverside instead. But I think there is some issues with the ID or something, but i can't figure out where. Is it a extjs bug?

frankbolviken
21 Sep 2011, 11:41 PM
this is the code that fails.. its in ext-debug-all.js

updateIndexes method:

for(var i = startIndex; i <= endIndex; i++){
ns[i].viewIndex = i;
ns[i].viewRecordId = records[i].internalId;
ext-all-debug.js:58747Uncaught TypeError: Cannot read property 'internalId' of undefined
ext-all-debug.js:58747Uncaught TypeError: Cannot read property 'internalId' of undefined
ext-all-debug.js:58747Uncaught TypeError: Cannot read property 'internalId' of undefined
ext-all-debug.js:58747Uncaught TypeError: Cannot read property 'internalId' of undefined
ext-all-debug.js:58747Uncaught TypeError: Cannot read property 'internalId' of undefined
if (!ns[i].boundView) {
ns[i].boundView = this.id;
}
}

tvanzoelen
22 Sep 2011, 1:55 AM
What happens if you specify the idProperty on the reader? Fill in there where to find the id in the returned JSON.

frankbolviken
22 Sep 2011, 2:03 AM
I managed to solve my problem. The issue was with my code which auto expanded rows with the path from history. It was called a couple of times, with the same path, which produced all kinds of wierd behaviour.

Thanks for the help tvanzoelen!