PDA

View Full Version : [4.0.7] Problem with expanding node in TreePanel



lukep1984
6 Dec 2011, 2:05 AM
Ext.define('Dict', {
extend: 'Ext.data.Model',
fields: [
{name:"id"},
{name:"text"},
{name:"leaf"},
{name:"expandable"},
{name:"expanded"}
],
associations: [
{type: 'hasMany', model: 'Dict', name: 'children'}
]
});

var countriesTreeStore = Ext.create('Ext.data.TreeStore', {
model: 'Dict',
proxy: {
type: 'ajax',
url: _root_url,
reader: {
type: 'json',
root: 'data'
},
},
root: {expanded: true, text: "Countries", leaf: false, id:"root"},
autoLoad : false
});

JSON:
{}&&{"data":[{"children":null,"expandable":true,"expanded":false,"id":4,"leaf":false,"text":"EU"},{"children":[{"expandable":true,"expanded":false,"id":5,"leaf":false,"text":"AAA"},{"expandable":true,"expanded":false,"id":6,"leaf":false,"text":"BBB"}],"expandable":true,"expanded":false,"id":41,"leaf":false,"text":"Argentina"}],"errors":null,"msg":null,"success":true,"targetUrl":null,"total":2}


var treePanel = Ext.create('Ext.tree.Panel', {
title: 'Countries',
width: 300,
height: 600,
scroll: 'both',
useArrows: true,
singleExpand: true,
renderTo : 'browseTree',
rootVisible: false,
store: countriesTreeStore
});

When I try to expand 'Argentina' node, I get the following error:

Uncaught TypeError: Cannot read property 'internalId' of undefined

Ext.define.updateIndexes ext-all-debug.js:60517
ext-all-debug.js:60470
fire ext-all-debug.js:10658
Ext.define.continueFireEvent ext-all-debug.js:13854
Ext.define.fireEvent ext-all-debug.js:13834
Ext.define.insert ext-all-debug.js:45162
Ext.define.onNodeExpand ext-all-debug.js:54195

Additionally while debuging I can see that childnodes element of 'Argentina' node looks empty.

I have no idea what I am doing wrong.
Any help would be appreciated.

Regards,
Luke

tvanzoelen
6 Dec 2011, 2:36 AM
plz use code tags. # button on the menu.

Probably you have duplicate ids in your data, the tree can not handle that. Check you JSON!

lukep1984
6 Dec 2011, 6:06 AM
You are right. The problem was in JSON.
When I changed JSON root name to 'children', it started to work well.
I was able to expand node.

But I decided to load every level of tree on expand, and I have experienced the same error while expanding.
JSON - first level:

{"children":[{"children":null,"expandable":true,"expanded":false,"id":"4-1","leaf":false,"text":"EU"},{"children":null,"expandable":true,"expanded":false,"id":"7-1","leaf":false,"text":"Afghanistan"},{"children":null,"expandable":true,"expanded":false,"id":"33-1","leaf":false,"text":"Aland Islands"}]}

JSON - second level:

{"children":[{"children":[{"expandable":true,"expanded":false,"id":"5-2","leaf":false,"text":"AAA"},{"expandable":true,"expanded":false,"id":"6-2","leaf":false,"text":"BBB"}],"expandable":true,"expanded":false,"id":"4-1","leaf":false,"text":"EU"},{"children":null,"expandable":true,"expanded":false,"id":"7-1","leaf":false,"text":"Afghanistan"},{"children":null,"expandable":true,"expanded":false,"id":"33-1","leaf":false,"text":"Aland Islands"}]}

I think that this time it regards to problem with refresh of view after loading treeStore.
I get index out of bounds records[i] at i=3 (image).

29825

Any help would be appeciated.

Regards,
Luke

tvanzoelen
6 Dec 2011, 7:08 AM
check if you have a double id on a node. if an id exists on another branche as well, you will get this error

for example node 4-1 you have in the first and in the second level.

lukep1984
6 Dec 2011, 11:24 PM
No, it's not this.

The second JSON is first JSON enriched with children for expanding node. The ids are unique within each JSON.

Any help would be appreciated.

Regards,
Luke

tvanzoelen
6 Dec 2011, 11:42 PM
It doesn't matter if the ids are unique within the JSON. It must be unique within the tree.

If you add the first json to the tree with for example the id 4_1 and you add the second json with again a node 4_1 then you have two nodes with the same id.

result, nodes that are not collapsing.

You can check it, if this is right. Then there should be no problem when you add the first JSON, and after adding the second json the collapsing error occurs.

lukep1984
7 Dec 2011, 12:02 AM
I thought that after expanding node (=reloading treestore) newly returned JSON replaces automatically the old one. Thus there can't be some problem with uniqueness of ids. The returned JSON is not appended to existing treestore, isn't it?

Should I make some manual clearing before reloading treestore?

Regards,
Luke

tvanzoelen
7 Dec 2011, 12:06 AM
By what you write, I see you reload a child node. If you expand a node, you load that specific node. The node allready in the tree will stay there.

If you expand or reload the root, all nodes in the tree will be removed.

lukep1984
7 Dec 2011, 2:21 AM
Thanks a lot. Your last reply is crucial!:-)