Ext實現點選節點,父子節點反選

livedba發表於2011-08-01
Ext實現點選節點,父子節點反選,核心程式碼:[@more@]

var root=new Ext.tree.AsyncTreeNode({
id:'root',
text:'許可權樹'
});
var orgTree=new Ext.tree.TreePanel({
animate:true,
useArrows:true,
frame:true,
autoScroll:true,
enableDD: false,
containerScroll: true,
rootVisible:false,
root:root,
listeners:
{
checkchange : function(node,checked){
checkChange(node,checked);
}
},

//監聽
var checkChange = function(node,checked){
checkParent(node,checked)//反選父節點
if(node.isLeaf()){
}else{
checkChild(node,checked);//反選子節點
}
}
//父節點反選
var checkParent = function(node,checked){
if(checked){

//判斷是否到了頂層父節點
if(node.parentNode!=null){
if(node.parentNode.attributes.checked){
node.parentNode.getUI().checkbox.checked = !checked;
}else{

}
checkParent(node.parentNode,checked);
}
}else{

}
}
//子節點反選
var checkChild = function(node,checked){
if(!node.hasChildNodes()){
return;
}else{
if(checked){
node.eachChild(function(child) {
child.getUI().checkbox.checked = !checked;
checkChild(child,checked);
});
}else{

}

}
}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25261409/viewspace-1053295/,如需轉載,請註明出處,否則將追究法律責任。

相關文章