PDA

View Full Version : Tree creates duplicate nodes



dekely
12 Oct 2013, 3:24 PM
Hi All,
I'm having issues with a very simple example. I tried to append a new node with children in runtime but the children are duplicated.
Appreciate your help.



Ext.onReady(function () {
var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "detention", leaf: true },
{ text: "homework", expanded: true, children: [
{ text: "book report", leaf: true },
{ text: "algebra", leaf: true}
] },
{ text: "buy lottery tickets", leaf: true }
]
}
});


Ext.create('Ext.tree.Panel', {
id: 'tree',
title: 'Simple Tree',
width: 200,
height: 350,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});


Ext.create('Ext.Button', {
text: 'Add Node To Root',
renderTo: Ext.getBody(),
handler: function() {
var newChildNode = { id: '11', text: 'new node', expanded: true, leaf: true };
var newNode = { id: '1', text: 'new node', expanded: true, children:[newChildNode] };
Ext.getCmp('tree').getRootNode().appendChild(newNode);
}
});


});

dekely
12 Oct 2013, 3:33 PM
Found IT!,
It happens because I specify an Id to a node.

Gary Schlosberg
14 Oct 2013, 4:54 AM
Glad you got it resolved, and thanks for taking the time to post a follow-up.