PDA

View Full Version : Treepanel - appenChild to node problem



burton449
10 Jun 2014, 9:26 AM
In my treepanel, I have a button to insert a Folder in the tree through an AJAX request. The AJAX response returns the id of the new inserted node (child_id) and the id of the parent of this node (parent_id).

Then, I use the parent_id to get its data.Record instance, and the appendChild method to create the new folder with the child_id.

The folder is created under the right node with the correct id, however, I dont know why but all the tree is inserted under that node as children. If I reload the tree from the server, everything is now correct.


var contextMenu = new Ext.menu.Menu({
items: [{
text: 'New Folder',
handler: function(thisBtn,event){
var tree = Ext.getCmp('tree');
var record = tree.getSelectionModel().getSelection();
var id = record[0].data.id;
Ext.Ajax.request({
url: '/basqui/tree/insertFolder',
method: 'POST',
params: { 'id': id },
success: function(r){
child_id = Ext.decode(r.responseText).child_id;
parent = store.getNodeById(Ext.decode(r.responseText).parent_id);
parent.appendChild({
id: child_id,
name: "New Folder",
type: "folder",
leaf: false
});
}
});
}
}]

burton449
10 Jun 2014, 9:46 AM
I found the solution, I have to set an empty children property in the node definition


parent.appendChild({
id: child_id,
name: "New Folder",
type: "folder",
leaf: false,
children: []
});