[Users] How to get unrendered child nodes

geographika geographika at gmail.com
Tue Dec 7 17:26:00 CET 2010


Have a look at the 
http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeLoader
The GeoExt.tree.LayerLoader inherits from this. You can create your own 
createNode function in a custom loader and you should be able to do what 
you want with it.
I'm not sure this is the recommended or easiest way but it gives you 
full control over how your nodes are loaded.

Project.CustomLoader = Ext.extend(GeoExt.tree.LayerLoader, {

     constructor: function(config){

         //config.preloadChildren = true;
         // apply config

         var customConfig = {
             preloadChildren: true
         };
         Ext.apply(config, customConfig);

        Project.CustomLoader.superclass.constructor.call(this, config);
         this.preloadChildren = true;
     },
     createNode: function(attr){
         if (this.baseAttrs) {
             Ext.apply(attr, this.baseAttrs);
         }

         //custom attributes
         attr.iconCls = attr.layer.iconCls;
         attr.qtip = attr.layer.qtip;
         attr.text = attr.layer.text;

         //same as original
         if (typeof attr.uiProvider == 'string') {
             attr.uiProvider = this.uiProviders[attr.uiProvider] || 
eval(attr.uiProvider);
         }
         attr.nodeType = attr.nodeType || "gx_layer";

         return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
     }

});

Then in your layer tree have something like:

{
                     "nodeType": "gx_overlaylayercontainer",
                     "expanded": false,
                     "text": "My Datasets",
                     "qtip": "My Datasets",
                     "loader": new Project.CustomLoader({
                         "baseAttrs": {},
                         filter: function(record){
                             var layer = record.get("layer");
                             if (layer._category) {
                                 return 
record.get("layer")._category.indexOf("forestry") !== -1;
                             }
                         },
                         listeners: {
                             "load": function(loader, node, reponse){
                                 //add sub overlay container
                                 //  ...


On 07/12/2010 16:49, Alexandre Dube wrote:
> Hi,
>
>     Thanks to both of you.  Your ideas helped a lot.
>
>     I'm still facing an other related problem.  When new OpenLayers.Layer
> objects are added, the according LayerNode is created as well
> (automatically by the LayerContainer).  Problem is : when I add a layer
> with "visibility": false, the parent node still keeps is node checked.
> I tried registering "append" and "insert" events on the layer node
> container when triggered, the new node isn't rendered yet.  I also tried
> (from there) to register a new node "render" and "afterrender" to manage
> the parent checkbox but it didn't work either (the event doesn't seem to
> trigger at all).
>
>     I'm beginning to lack ideas...  Any hints ?
>
> Thanks again,
>
> Alexandre
>
>
>
> On 10-12-07 07:26 AM, Eric Lemoine wrote:
>> On Mon, Dec 6, 2010 at 10:04 PM, Alexandre Dube<adube at mapgears.com>   wrote:
>>
>>> Hi,
>>>
>>>     This is more a Ext question, but since I know this is a good resource
>>> place...
>>>
>>>     When a TreeNode hasn't been expanded yet, none if its child nodes are
>>> created so I don't have a way to know which one if 'checked' to check
>>> the parent accordingly (if all child nodes are checked).
>>>
>>>     How can I access the uncreated child nodes ?
>>>
>> Hi Alexandre
>>
>> For a project of mine I had to do things like this:
>>
>>       setSelectedNode: function() {
>>           this.root.cascade(function(n) {
>>               var expanded = n.isExpanded();
>>               if (!expanded) {
>>                   n.expand();
>>               }
>>               if (n.id == this.selectedNodeId) {
>>                   this.selectNode(n);
>>                   n.ensureVisible();
>>                   this.selectedNode = n;
>>                   return false;
>>               } else if (!expanded) {
>>                   n.collapse();
>>               }
>>           }, this);
>>       },
>>
>> I'm not sure this can help you...
>>
>> Good luck!
>>
>>
>>
>



More information about the Users mailing list