<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Seth,<br>
<br>
The themes and theme variables are defined before the loop. I have
just done some further testing: When the filter function is called
it will always use the last setting of the "theme" variable. So the
filter function is not used within the loop, but afterwards. <br>
<br>
As an example, let's assume the themes are 'vegetation', 'water' and
'roads'. I want to loop through those themes and build
GeoExt.tree.LayerContainer nodes where the theme matches a layer
property. What I see now is that the value 'roads' is always used
for matching because it is the last value in the theme array. <br>
<br>
In Firebug I see that the line with the filter function is executed
at the moment when I expand the node. So that is completely after
the loop. I see the the line is called outside the loop if I set
"expanded: true", too.<br>
<br>
My approach is obviously wrong but I have no idea how to progress.
Could there be a way of creating LayerContainers in a loop that use
loaders that match with a literal instead of a variable?<br>
<br>
Frans<br>
<br>
On 2011-02-11 11:53, geographika wrote:
<blockquote cite="mid:4D55152F.4070404@gmail.com" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
Hi,<br>
<br>
Where are your themes and theme variables defined? They will need
to be in the scope of the filter function to work correctly. <br>
Try putting a debugger; statement in to see exactly what is in
these variables (I'd imagine undefined at the moment). <br>
<pre wrap="">filter: function(record){
        debugger;
return (record.get("layer").options.themeId == themes[theme].id);
}
</pre>
Regards,<br>
<br>
Seth<br>
--<br>
<font color="#888888"> web:</font><a moz-do-not-send="true"
href="http://geographika.co.uk"><font color="#888888"> </font>http://geographika.co.uk</a><br>
<font color="#888888">twitter: @geographika<br>
</font><br>
On 11/02/2011 11:32, Frans Knibbe wrote:
<blockquote cite="mid:4D55102D.6010002@geodan.nl" type="cite">
<pre wrap="">Hello!
I am trying to create several GeoExt.tree.LayerContainer nodes in my
layer tree. I want to group layers by a custom attribute (themes) that I
have added to the OpenLayers layer definition. Let's call this attribute
'themeId'. It could have values like 'vegetation', 'water', 'roads',
etc.. What I want to do is loop though the themes and create
.LayerContainers for matching layers. I am doing this by means of a
filter of the GeoExt.tree.LayerLoader, which looks like this:
filter: function(record){
return (record.get("layer").options.themeId == themes[theme].id);
}
My problem is that the filter does not work :-). This seems to be caused
by the variable holding the theme ID ( themes[theme].id in the example
above) being unknown at them time the filter function is executed. If I
exchange the variable with a string everything works fine, like this:
filter: function(record){
return (record.get("layer").options.themeId == 'vegetation');
}
So my question is: Can I somehow get the variable to have the right
value at the time the filter function is executed? Or is there another
way of dynamically building LayerContainers I could try?
Thanks!
Frans
_______________________________________________
Users mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Users@geoext.org">Users@geoext.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.geoext.org/cgi-bin/mailman/listinfo/users">http://www.geoext.org/cgi-bin/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@geoext.org">Users@geoext.org</a>
<a class="moz-txt-link-freetext" href="http://www.geoext.org/cgi-bin/mailman/listinfo/users">http://www.geoext.org/cgi-bin/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
</body>
</html>