ext3.0 中怎样实现选中一个节点把他相应的子节点和父节点都选中,用checkTreePane自带的实现总有问题,
checktreepanel中自带的有相关属性bubblecheck:none/checked/unchecked,cascadecheck:none/checked/u...
checktreepanel中自带的有相关属性bubblecheck: none/checked/unchecked, cascadecheck: none/checked/unchecked/all 事件是onCheckChange 如果用自带的updateChild();方法 和updateParent()方法 当属性选中bubbleCheck:'none',cascadeCheck:'all',时 只执行updateChild()方法能实现子节点全部选中,如果把updateParent方法也加上 向下遍历时只选中前根节点的前两个,再向下就不能选中了,部分代码如下:
,setChecked:function(checked) {
checked = true === checked ? checked : false;
var cb = this.cbEl || false;
if(cb) {
true === checked ? cb.addClass('x-tree-node-checked') : cb.removeClass('x- tree-node-checked');
}
this.node.attributes.checked = checked;
this.onClick();
return checked;
}
updateParent:function(checked) {
var p = this.node.parentNode;
var ui = p ? p.getUI() : false;
if(ui && ui.setChecked) {
ui.setChecked(checked);
}
}
updateChildren:function(checked) {
this.node.eachChild(function(n) {
var ui = n.getUI();
if(ui && ui.setChecked) {
ui.setChecked(checked);
}
});
}
onCheckChange:function() {
var checked = this.isChecked();
var tree = this.node.getOwnerTree();
var bubble = tree.bubbleCheck;
var cascade = tree.cascadeCheck;
if('all' === bubble || (checked && 'checked' === bubble) || (!checked && 'unchecked' === bubble)) {
this.updateParent(checked);
}
if('all' === cascade || (checked && 'checked' === cascade) || (!checked && 'unchecked' === cascade)) {
this.updateChildren(checked);
}
tree.updateHidden();
this.fireEvent('checkchange', this.node, checked);
}
由于字数有限注释没有加上 展开
,setChecked:function(checked) {
checked = true === checked ? checked : false;
var cb = this.cbEl || false;
if(cb) {
true === checked ? cb.addClass('x-tree-node-checked') : cb.removeClass('x- tree-node-checked');
}
this.node.attributes.checked = checked;
this.onClick();
return checked;
}
updateParent:function(checked) {
var p = this.node.parentNode;
var ui = p ? p.getUI() : false;
if(ui && ui.setChecked) {
ui.setChecked(checked);
}
}
updateChildren:function(checked) {
this.node.eachChild(function(n) {
var ui = n.getUI();
if(ui && ui.setChecked) {
ui.setChecked(checked);
}
});
}
onCheckChange:function() {
var checked = this.isChecked();
var tree = this.node.getOwnerTree();
var bubble = tree.bubbleCheck;
var cascade = tree.cascadeCheck;
if('all' === bubble || (checked && 'checked' === bubble) || (!checked && 'unchecked' === bubble)) {
this.updateParent(checked);
}
if('all' === cascade || (checked && 'checked' === cascade) || (!checked && 'unchecked' === cascade)) {
this.updateChildren(checked);
}
tree.updateHidden();
this.fireEvent('checkchange', this.node, checked);
}
由于字数有限注释没有加上 展开
1个回答
展开全部
//这个方法是选择父节点,自动选中所有的子节点
function selParent(node, checked) {
node.expand();
//checked ? node.expand() : node.collapse();
if (node.hasChildNodes()) {
node.eachChild(function(child) {
child.attributes.checked = checked;
var cb = child.ui.checkbox;
if (cb)
{
cb.checked = checked;
}
selParent(child, checked);
});
};
}
//这个方法是选择子节点,自动选中父节点的父节点
function selChild(node, checked) {
if (checked) {
node.expand();
var parentNode = node.parentNode;
if (parentNode != undefined) {
parentNode.attributes.checked = checked;
var cb = parentNode.ui.checkbox;
if (cb)
{
cb.checked = checked;
}
selChild(parentNode, checked);
}
}
}
tree.on('checkchange', function(node, checked){
selParent(node, checked);
selChild(node, checked);
},tree);
很久以前写的了可以用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询