Results 1 to 3 of 3

Thread: hasChildNodes()??????

  1. #1
    Ext User
    Join Date
    Jul 2009
    Posts
    108

    Default hasChildNodes()??????

    I create 2 function, one for add the node of tree, one for remove the node of tree, the code is:

    Code:
    var root = new Ext.tree.TreeNode({
    text        : 'Project',
     id          : 'rootProject',
     leaf        :false,
     expandable  : true,
     expanded    : true
    })
    	
    var addNodoModello=function(testo,id){
    if(root.findChild('id',id)==null){
    root.appendChild([{
    text: testo,
    id  : id,
    leaf: false
    }]);
    }
    }
    
    var removeNodoModello=function(id){
    var app=root.findChild('id',id);
    if(app.hasChildNodes()){
    root.findChild('id',id).remove();
    }
    
     var tree = new Ext.tree.TreePanel({
      id: 'contenitoreAlbero',
      autoScroll: true,
      split: true,
      animate: true,
      collapseFirst: false,
      useArrows: true,
      enableDrag: false,
      root: root,
      rootVisible: true
    })
    
    var contenitoreAlbero=new Ext.Panel({
    id: 'pannelloContenitoreAlbero',
    title: 'Project Tree',
    tbar: [{
    	text:'UML',
    	handler: function(){addNodoModello('UML','idUML');}
    	},{
    	text: 'rem UML',
    	handler: function(){removeNodoModello('idUML');}
    	}],
    items: [tree]
    });
    }

    The nodes, has the option "leaf: false" because I add other nodes to those generated.
    When the node hasn't child I aspect with the method : "hasChildNodes()" give me the value "false" instead his give me "true"......I don't undestand why?
    Last edited by Condor; 24 Jul 2009 at 3:10 AM. Reason: Please post using [CODE] tags!

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    You are creating an AsyncTreeNode instead of a TreeNode. Since you didn't specify loaded:true, hasChildNodes will always return true.

    You want:
    Code:
    root.appendChild([new Ext.tree.TreeNode({
      text: testo,
      id  : id,
      leaf: false
    })]);

  3. #3
    Ext User
    Join Date
    Jul 2009
    Posts
    108

    Default

    Condor Thanks......I and tree don't LOVE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •