<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 10pt">
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><FONT face=Tahoma><B>From:</B> </FONT><A
title=p.scadden@gns.cri.nz href="mailto:p.scadden@gns.cri.nz"><FONT
face=Tahoma>Phil Scadden</FONT></A><FONT face=Tahoma> </FONT></DIV>
<DIV><FONT face=Tahoma><B>Sent:</B> Wednesday, July 13, 2011 4:31
PM</FONT></DIV>
<DIV><FONT face=Tahoma><B>To:</B> </FONT><A title=users@geoext.org
href="mailto:users@geoext.org"><FONT
face=Tahoma>users@geoext.org</FONT></A><FONT face=Tahoma> ; </FONT><A
title=adube@mapgears.com href="mailto:adube@mapgears.com"><FONT
face=Tahoma>Alexandre Dube</FONT></A><FONT face=Tahoma> </FONT></DIV>
<DIV><FONT face=Tahoma><B>Subject:</B> Re: [Users] Layertreebuilder has issues
when layer removed.</FONT></DIV></DIV>
<DIV>></DIV><FONT face=Calibri><FONT style="FONT-SIZE: 12pt">>In meantime
I have "almost works" code in my main code of:<BR>>for (var i = 0;
i<tree.getRootNode().childNodes.length; i++) {<BR>>if
(tree.getRootNode().childNodes[i].childNodes.length==0)
{<BR>>tree.getRootNode().childNodes[i].remove();<BR>>}<BR>>}<BR>><BR>>but
this only works if I have only one level of grouping. If you can <BR>>give me
any pointers as to a better way to proceed, I am very willing to <BR>>try
them out.</FONT></FONT>
<DIV> </DIV>
<DIV>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. </DIV>
<DIV>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.</DIV>
<DIV>You should change your function to this:</DIV>
<DIV><FONT face=Calibri><FONT style="FONT-SIZE: 12pt"></FONT></FONT> </DIV>
<DIV><FONT face=Calibri><FONT
style="FONT-SIZE: 12pt">tree.getRootNode().cascade(function(node){<BR>
if (!node.childNodes || node.childNodes.length==0)
{<BR> node.remove();<BR>
}</FONT></FONT></DIV>
<DIV><FONT face=Calibri><FONT style="FONT-SIZE: 12pt">}</FONT></FONT><BR></DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 10pt">Matt
Priour<BR>Kestrel Computer Consulting</DIV></DIV></DIV></BODY></HTML>