Ext.onReady(function (){
var treepanel = new Ext.tree.TreePanel({
autoScroll : true,
animate : true,
autoShow:true,
collapsible:true,//设置树根节点展开
enableDD : true,
containerScroll:true,
width:150,
height : 500,
lines:true,//各节点通过线连接起来
id:'treePanel'
});
var rootTreeNode = new Ext.tree.TreeNode({
id:"rootType",
text:"类别",
expanded:true
});
for(var i=0; i<10; i++){
var childTreeNode = new Ext.tree.TreeNode({
id:"rootType"+i,
text:"文史类"+i
});
for(var j=0; j<5;j++){
var leafTreeNode = new Ext.tree.TreeNode({
id:"leafType"+i,
text:"语文"+i,
leaf:true
});
childTreeNode.appendChild(leafTreeNode);//为节点添加子节点
}
rootTreeNode.appendChild(childTreeNode);
}
treepanel.setRootNode(rootTreeNode);//将根节点与树关联起来
var filter = new Ext.tree.TreeFilter(treepanel, {
clearBlank: true,
autoClear: true
});
filter.filterBy(function(n){
if(n.text.indexOf("3") !=-1){//过滤了包含"3"的一级子节点
return false;
}else{
return true;
}
});
treepanel.addListener("click",function(node,e){//为树添加单击事件
if(node.isLeaf()){//判断是否是叶节点
//alert(node.text);//获取叶节点的文本值
// alert(treefilter.filter("1","text",node));
}
});
//rootTreeNode.expandAll();
//rootTreeNode.expandChildNodes(true);
var window =new Ext.Window({
//contentEl : "winwinwin",
html:"<div id='treeNode'></div>",
width : 150,
draggable:false,
height : 530,
//layout:'border',
modal:true,
closeAction:'hide',
items :[ new Ext.Panel( {
id:'treepanelss',
region : 'west',
split : true,
title : '物资类别',
width : 150,
height : 450,
autoScroll : false,
collapsible : true,
items : [treepanel]
})
],
plain : true,// true则主体背景透明,false则主体有小差别的背景色,默认为false
title : "选择物资"
});
window.show();
}
);