[Users] Layertreebuilder has issues when layer removed.
Matt Priour
mpriour at kestrelcomputer.com
Thu Jul 14 04:46:05 CEST 2011
From: Phil Scadden
Sent: Wednesday, July 13, 2011 4:31 PM
To: users at geoext.org ; Alexandre Dube
Subject: Re: [Users] Layertreebuilder has issues when layer removed.
>
>In meantime I have "almost works" code in my main code of:
>for (var i = 0; i<tree.getRootNode().childNodes.length; i++) {
>if (tree.getRootNode().childNodes[i].childNodes.length==0) {
>tree.getRootNode().childNodes[i].remove();
>}
>}
>
>but this only works if I have only one level of grouping. If you can
>give me any pointers as to a better way to proceed, I am very willing to
>try them out.
I’ve used a similar clean-up function in some projects. I run it on the ‘remove’ event on the layer tree with a delay of 250ms.
You should not walk an Ext.tree.TreePanel with a normal javascript loop like that. ExtJS provides several tree traversal methods that will work with any level of nesting.
You should change your function to this:
tree.getRootNode().cascade(function(node){
if (!node.childNodes || node.childNodes.length==0) {
node.remove();
}
}
if you need to only hit a specific area of the tree and don’t want/need to walk the whole tree then use node.eachChild() with a recursive version of the above anonymous function.
Matt Priour
Kestrel Computer Consulting
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20110713/33a6f230/attachment.htm
More information about the Users
mailing list