Results 1 to 7 of 7

Thread: When can I call getNodeById()

  1. #1

    Default When can I call getNodeById()

    So I have TreePanel. I get JSON data all at once, does that mean that the tree is fully loaded?
    Suppose there is node A, and is has child node B. when I view A in firebug without expanding it, I can see that it has children. But, tree.getNodeById('B') still returns undefined, why is that? it returns B only after A is expanded.

    But I don't want to show A as expanded. I was thinking to expand all nodes and then collapse them, cause I need to access those inner nodes without showing the tree as expanded. Any ideas?
    doing tree.expand(true); tree.collapse(true); doesn't work I guess because i call collapse while the nodes are expanding. So in this case the question is when should I call collapse(true)?


  2. #2


    You should check the differences between the AsyncTreeNode and the TreeNode. That describes some of what you're describing.

    We can't actually help you when you don't give us a code snippet, but are you attempting to call getById on a tree before it loads, and then seeing that it's loaded in firebug, after the fact? Generally, you'd add a listener for the event you want to use to trigger your function. You can use the tree loader's load event, I think, in this case, to call getById, which should then respond properly. Again, without seeing your code, it's difficult to provide correct assistance.

    And finally, the json nodes coming back can defined "expanded: false" i believe, check the docs. Also the use of the leaf property is important to defining what is expandable.

  3. #3
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    The Netherlands


    So your server is returning all nodes AND all child nodes (as 'children') in one single request?

    Did you configure your TreeLoader with preloadChildren:true?

    Even after doing this, you still have to wait for the load (or expand) event on the root node before you can access child nodes.

  4. #4


    First, thanks for replies. here is the code:

    var tree = new Ext.tree.TreePanel({
            title: 'The Tree',
            height: 300,
            width: 400,
            rootVisible: false,
            root: { },
            loader : new Ext.tree.TreeLoader({
                 dataUrl: 'check-nodes.json',
                 preloadChildren : true
    and check-nodes.json has

        text: 'To Do', 
        cls: 'folder',
        id: 'todo',
        children: [{
            text: 'Go jogging',
            leaf: true,
            checked: false,
            text: 'Take a nap',
            leaf: true,
            checked: false,
            id: 'nap'
    }, ....
    why doesn't it load everything at once? I did add preloadChildren = true on the loader?
    the button is there just for testing, i click on it after everything is loaded and firebug shows that 'todo' node is loaded = false

  5. #5
    Sencha User boolean's Avatar
    Join Date
    Aug 2007
    china beijing


    yes, i met the same problom, waiting for help

  6. #6


    after looking into the code i discovered that calling load function will load with loadChildren = true will load all the way down, but not if that node is the root, so i call load on every child of the root node, which will load the whole tree.
    add listener to 'load':

    if( == 'src'){
        for(i=0; i < node.childNodes.length; i++){
               var n = node.childNodes[i];
    it seems to work but if anybody finds a better solution, please post)

  7. #7
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    The Netherlands


    This is weird. That is exactly what preloadChildren should be doing...

Similar Threads

  1. getNodeById returns 'undefined'
    By jaforom in forum Ext 2.x: Help & Discussion
    Replies: 12
    Last Post: 10 Jun 2009, 3:24 AM
  2. TreePanel.getNodeById not recursive ?
    By cblin in forum Ext 2.x: Help & Discussion
    Replies: 10
    Last Post: 31 Mar 2008, 7:53 AM
  3. TreePanel.getNodeById() fails
    By murraybozinsky in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 25 Feb 2008, 4:03 AM
  4. Bug in TreeView.getNodeById
    By booshan in forum Ext 2.x: Help & Discussion
    Replies: 8
    Last Post: 20 Aug 2007, 5:31 AM

Posting Permissions

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