PDA

View Full Version : Delete recently added leaf on a tree



eaglefox12
4 Jan 2013, 7:25 AM
I have a tree and each time a leaf is added to a node, I do an ajax call. It works fine but when it fails, on failure function, the leaf is still added even though the error message that I put shows up.. so what I want to do is on failure function I want to remove that added leaf... I did this but this does not work


var temp2 = Ext.StoreMgr.lookup('myStore').tree.root.childNodes[0];
console.log(temp2);
Ext.StoreMgr.lookup('myStore').tree.root.removeChild(temp2);

is there a better way to do this?

sencha-dev2
4 Jan 2013, 7:33 AM
Hi, I used this to destroy a leaf on a tree panel when I close the corresponding tab.



var root = Ext.getCmp('treePrincipal').getRootNode();
var parent = root.findChild('id', 'rootBeneficiaire');
var child = parent.findChild('id', this.id);
child.destroy();


It works well on a beforeclose event, I think you can adapt to your case.
The properties you set on your treepanel can help you to find its elements, do NOT use this.id as you probably won't refer to the node. I set mine in order to have the same ids for my panel and the corresponding node.
Hope it'll help.

vicvolk
4 Jan 2013, 7:37 AM
I'm not sure, but simply try


temp2.remove();

eaglefox12
4 Jan 2013, 10:31 AM
I tried but it refreshes my tree but the leaf is still there