日期:2014-05-16 浏览次数:20410 次
Ext.require(['*']);
Ext.onReady(function(){
var data = [
{
"text": "To Do",
"cls": "folder",
"expanded": true,
"children": [{
"text": "Go jogging",
"leaf": true
},{
"text": "Take a nap",
"leaf": true
},{
"text": "Climb Everest",
"leaf": false,
"children":[{"text":"Go Shopping","leaf":true}]
}]
},{
"text":"Go Hiking",
"cls":"folder",
"leaf":true
}]
var store2 = Ext.create('Ext.data.TreeStore', {
root: {
text: 'Custom Ext JS',
id: 'src',
expanded: true,
children: data
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
function iterNodes(rootnodes){
for(var i=0;i<rootnodes.length;i++){
rootnodes[i].data.checked=false //设置checkebox
if(rootnodes[i].childNodes.length>0){
iterNodes(rootnodes[i].childNodes) //如果有子节点就递归。
}
}
}
var tree2 = Ext.create('Ext.tree.Panel', {
id: 'tree2',
width: 250,
height: 300,
store: store2,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
appendOnly: true
}
},
renderTo: document.body,
listeners:{
render:function(t){
var tree = t.store;
var rootnodes = tree.getRootNode().childNodes;//获取主节点
iterNodes(rootnodes);
}
}
});
});