如何向Ext.tree.TreePanel添加复选框?

时间:2010-09-01 17:27:47

标签: extjs checkbox tree

我创建了这个简单的树:

var children = [{
         text:'My Layers',
         children:[
           new Ext.tree.TreeNode({text:'test1',leaf:true}),
           new 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
       })
    });

如何向每个节点添加复选框?

实际上我要将列表作为参数传递给JSON数组中的函数(例如[“test1”,“test2”])。从JSON数据加载节点的正确方法是什么?

我正在使用ExtJs 2.3和GeoExt。

干杯!

2 个答案:

答案 0 :(得分:4)

答案 1 :(得分:3)

您可以在节点级别设置'checked:true / false'以显示复选框。 最初它设置为 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**})
    ]
}];