coolite TreePanel CheckBox联动

本文介绍了一种在ExtJS中实现树形面板中复选框状态同步的方法。通过递归函数实现了子节点状态改变时父节点的状态更新,并在父节点状态变化时同步所有子节点的状态。

ContractedBlock.gifExpandedBlockStart.gif代码
<Listeners>

<CheckChange Handler="treepanelcheck(node)" />
</Listeners>

 

ContractedBlock.gifExpandedBlockStart.gif代码
function treepanelcheck(item) {

treepanelchildcheck(item);
treepanelparentcheck(item);
}
function treepanelchildcheck(item) {
var chNode;

if (item.childNodes.length > 0) {
if (item.attributes.checked == true) {
for (var i = 0; i < item.childNodes.length; i++) {
chNode
= item.childNodes[i];
chNode.attributes.checked
= true;
chNode.getUI().checkbox.checked
= true;


}
}
if (item.attributes.checked == false) {
for (var i = 0; i < item.childNodes.length; i++) {
chNode
= item.childNodes[i];
chNode.attributes.checked
= false;
chNode.getUI().checkbox.checked
= false;

}
}
}
}
function treepanelparentcheck(item) {
var chNode;
var checkBool;
if (item.parentNode.parentNode != null) {
if (item.attributes.checked == false) {

for (var i = 0; i < item.parentNode.childNodes.length; i++) {

chNode
= item.parentNode.childNodes[i];
if (chNode.attributes.checked == true) {
checkBool
= true;
break;
}

//chNode.attributes.checked = true;

}
if (checkBool == true) {
item.parentNode.attributes.checked
= true;
item.parentNode.getUI().checkbox.checked
= true;
}
else {
item.parentNode.attributes.checked
= false;
item.parentNode.getUI().checkbox.checked
= false;
}
}
if (item.attributes.checked == true) {
item.parentNode.attributes.checked
= true;
if (item.parentNode.getUI().checkbox != null) {
item.parentNode.getUI().checkbox.checked
= item.attributes.checked;
}
}
}
}

 

转载于:https://www.cnblogs.com/hanli/archive/2010/06/10/1755796.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值