Blog.

How to build a Tree from static data

Code in this post can be obsolete, however, principles and theory may still apply.



  
  
  
  
  
  
  
  
  
Ext.BLANK_IMAGE_URL = '../ext/resources/images/default/s.gif';
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

var children = [{
     text:'First Level Child 1'
    ,children:[{
         text:'Second Level Child 1'
        ,leaf:true
    },{
         text:'Second Level Child 2'
        ,leaf:true
    }]
},{
     text:'First Level Child 2'
    ,children:[{
         text:'Second Level Child 1'
        ,leaf:true
    },{
         text:'Second Level Child 2'
        ,leaf:true
    }]
    
}];
Ext.onReady(function(){
    var tree = new Ext.tree.TreePanel({
         loader:new Ext.tree.TreeLoader()
        ,width:200
        ,height:400
        ,renderTo:Ext.getBody()
        ,root:new Ext.tree.AsyncTreeNode({
             expanded:true
            ,leaf:false
            ,text:'Tree Root'
            ,children:children
        })
    });
});  
  
  Building A Tree From Static Data






saki
Follow me:
Latest posts by saki (see all)

17 Responses

  1. Saki,

    You’ve got some great examples and are a great asset to those learning Ext. Could you please update this example so that it will correctly work with Ext 2.2. Line 61 in your js source above should be removed and it will work like a charm again.

  2. hai saki…
    i have some problems with the panel.
    i have the dinamic tree (base on database), when i click the node (output is url to an extjs formPanel’s file), i want this formPanel to be displayed to a panel.
    but the fact, the formPanel wouldnot render/appear to that panel…:(
    please help me..
    thanks
    regards

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your username and password to log into your account. Don't have an account? Sign up.

Want to collaborate on an upcoming project?