9

I would like to know how can i check the sibling nodes of a tree while clicking on a particular node in ExtJs.

I had given id's for each node and i can access the id of a clicked node. then how can i proceed to checking the child nodes automatically ??

somebody please help me..

4

7 回答 7

7
// or any other way of getting hands on the node you want to work with
var node = treePanel.getNodeById('your-id');
node.eachChild(function(n) {
    n.getUI().toggleCheck(true);
});

如果你想让它在当前节点的整个子树上工作,你必须做一些递归。

更集成一点:

treePanel.on('checkchange', function(node, checked) {
    node.eachChild(function(n) {
        n.getUI().toggleCheck(checked);
    });
});
于 2010-02-16T15:39:27.830 回答
5
function nodeCheck(node) {
    node.eachChild(function(n) {
        if(n.hasChildNodes())
            nodeCheck(n)
        n.getUI().toggleCheck(false);
    });
}
var node = (tree.getSelectionModel().getSelectedNode()) ? tree.getSelectionModel().getSelectedNode() : tree.root;
if(node) nodeCheck(node);

这对我来说很有效 ;)

于 2010-09-20T12:56:37.507 回答
2

听众:{

checkchange : function(node, checked) {
    node.parentNode.cascadeBy(function(n){n.set('checked', checked);});
}

}

于 2011-12-30T06:01:40.827 回答
1
function checkChange(node, checked, Object) {
    node.cascadeBy(function(n) {
        n.set('checked', checked);
    });
}
于 2012-08-30T22:15:53.947 回答
1

C 先生的答案工作正常(ExtJS 4.2),但是当父节点的子节点有 1 个子节点时会出现错误。这是我的一点改进。有人可以进一步改进

function (node, checked) {

    if (node.isLeaf()) {
        node = node.parentNode;
        var siblingStateEqual = true;
        if (node.childNodes.length == 1) {
            siblingStateEqual = checked;
        } else {
            node.cascadeBy(function (n) {
                if (n != node) {
                    if (n.get('checked') != checked) {
                        siblingStateEqual = false;
                    }
                }

            });
        }

        if (siblingStateEqual == checked) {
            node.set('checked', checked);
        }

    }
    else {
        node.cascadeBy(function (n) {
            n.set('checked', checked);
        });
    }
}
于 2013-09-20T02:34:16.993 回答
0

当您填充节点时,JSON 或 XML 需要将“checked”属性设置为 true 或 false。我假设您正在使用 AsyncTreeNode 为您执行此操作。如果创建树节点时不存在此选中属性,ExtJS 将不会使用复选框呈现它。

于 2010-09-08T05:13:32.093 回答
-1

或者,如果像我一样,您需要在选中/取消选中所有子叶节点时自动选中/取消选中父节点,您可以试试这个:

function (node, checked)
{

    if (node.get('leaf'))
    {
        node = node.parentNode;
        var siblingStateEqual = true;
        node.cascadeBy(function (n)
        {
            if (n != node) {
                if (n.get('checked') != checked) {
                    siblingStateEqual = false;
                }
            }

        });

        if (siblingStateEqual == checked)
        {
            node.set('checked', checked);
        }

    }
    else
    {
        node.cascadeBy(function (n) { n.set('checked', checked); });
    }


}
于 2013-02-20T17:31:52.387 回答