PDA

View Full Version : [FIXED-422][3.1] Tree node remove() acting strange



Lobos
3 Jan 2010, 2:18 PM
tree.getNodeById('src').eachChild(function(n){
n.remove();
});


I tried this on the example and it is not removing all the nodes.

http://www.extjs.com/deploy/dev/examples/tree/reorder.html

gives an error then stops, if you keep using the above procedure it will remove several more then stop until there are none left. Strange.


TypeError: n is undefined

A temporary fix hint would be appreciated or a red face :"> if I am not doing this right ;)

3.1 is shaping up great btw, I been having a good play with Ext.direct and it is awesome, thanks a lot.

-Lobos

Lobos
3 Jan 2010, 2:45 PM
This recursive function seems to do the trick:


var removeAllChildren = function(parent){
parent.eachChild(function(n){

if(n && parent.hasChildNodes()){
n.remove();
removeAllChildren(parent);
}

});
}
removeAllChildren(tree.getNodeById('src'));

Jazor
14 Jan 2010, 4:29 AM
I'm also experiencing what seems to be a bug in 3.1.0.

Invoking this works once, but then fails on any attempt to remove siblings of aNode:


aNode.remove()I believe the error occurs in Ext.data.Node (ext-3.1.0/src/data/Tree.js):


remove : function(destroy) {
this.parentNode.removeChild(this, destroy);
return this;
},
The error in Firebug is this.parentNode is null.

I'm testing under Firefox 3.0.17.

Condor
15 Jan 2010, 12:29 AM
eachChild() doesn't make a copy of the children before processing them, so adding or removing children in the callback will break eachChild.

How does this work:

var childNodes = [].concat(tree.getNodeById('src').childNodes);
Ext.each(childNodes, function(n){
n.remove();
});

Jazor
15 Jan 2010, 5:19 AM
To follow up on my post above:

I didn't get to the bottom of the problem but did avoid it by reorganising the structure of components.

I have a TreePanel and a 'content' CardLayout panel with sub CardLayout panels.

Originally each child panel in the content panel managed its own TreePanel node. Each new child panel was given a reference to its parent and was responsible for creating and removnig its own node.

My approach now is that the top level content panel manages the nodes and child panels do not have references to their own nodes.

I'm not sure if I experienced a bug or if in fact it was a misunderstanding on my part.

evant
17 Jan 2010, 11:38 AM
@Jazor: I think you're talking about something completely different. If you feel there's an issue, please create a new thread with a proper bug report.

@OP: There should probably be a removeAll method on the Node class itself to handle this.

Stay tuned ;)

Jazor
17 Jan 2010, 12:06 PM
I haven't been able to recreate the problem with a simple example, so more likely a bug in my code than an Ext JS bug.

And yes, I agree not a the same problem as Lobos. I was a bit hasty with my post.

evant
17 Jan 2010, 6:48 PM
A new removeAll method was added in rev 5904.