开发者

How to add checkboxes to Ext.tree.TreePanel?

开发者 https://www.devze.com 2023-01-13 21:07 出处:网络
I created this simple tree: var children = [{ text:\'My Layers\', children:[ new Ext.tree.TreeNode({text:\'test1\',leaf:true}),

I created this simple tree:

var children = [{
         text:'My Layers',
         children:[
           new Ext.tree.TreeNode({text:'test1',leaf:true}),
           开发者_如何学Pythonnew Ext.tree.TreeNode({text:'test2',leaf:true})
        ]
    }];
    var tree = new Ext.tree.TreePanel({
       loader:new Ext.tree.TreeLoader(),
       width:150,
       title:'Layers',
       height:250,
       collapsible:true,
       rootVisible:false,
       root: new Ext.tree.AsyncTreeNode({
           expanded:true,
           leaf:false,
           text:'Tree Root',
           children:children
       })
    });

How can I add a Checkbox to each node?

Actually I'm gonna pass the list as a parameter to the function in a JSON array (e.g. ["test1","test2"]). What is the proper way to load nodes from JSON data?

I'm using ExtJs 2.3 with GeoExt.

Cheers!


http://dev.sencha.com/deploy/dev/examples/tree/check-tree.html

The EXTJS library has an example of just that.


You can set 'checked: true/false' at the node level to bring the checkbox. Initially it is set to null.

var children = [{
     text:'My Layers',
     children:[
       new Ext.tree.TreeNode({text:'test1',leaf:true, **checked: true**}),
       new Ext.tree.TreeNode({text:'test2',leaf:true, **checked: false**})
    ]
}];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号