1
tree.on('checkchange', function(node, checked)
{
2
selParent(node, checked);
3
selChild(node, checked);
4
}, tree);
5
//这个方法是选择父节点,自动选中所有的子节点
6
function selParent(node, checked)
{
7
checked ? node.expand() : node.collapse();
8
if (node.hasChildNodes())
{
9
node.eachChild(function(child)
{
10
child.attributes.checked = checked;
11
var cb = child.ui.checkbox;
12
if (cb) cb.checked = checked;
13
selParent(child, checked);
14
});
15
}
16
}
17
18
//这个方法是选择子节点,自动选中父节点的父节点
19
function selChild(node, checked)
{
20
if (checked)
{
21
node.expand();
22
var parentNode = node.parentNode;
23
if (parentNode != undefined)
{
24
parentNode.attributes.checked = checked;
25
var cb = parentNode.ui.checkbox;
26
if (cb) cb.checked = checked;
27
selChild(parentNode, checked);
28
}
29
}
30
}
posted on 2011-03-24 17:53
CLOG 阅读(537)
评论(0) 编辑 收藏