简体   繁体   English

dojo dijit.tree getChildren() 不返回所有树节点

[英]dojo dijit.tree getChildren() not returning all tree nodes

I am using dojo 1.10.4 and have noticed that the dijit.tree getChildren() function only returns children (tree) nodes that are expanded (displayed and visible) in the dijit.tree.我正在使用 dojo 1.10.4 并且注意到 dijit.tree getChildren() 函数只返回在 dijit.tree 中展开(显示和可见)的子(树)节点。 How can I loop through all of the dijit.tree tree nodes regardless of whether or not they are displayed and visible?如何循环遍历所有 dijit.tree 树节点,而不管它们是否显示和可见?

  • I can easily loop through all of the underlying data store elements but I am trying to locate specific tree nodes so that I can style them using "node.labelNode.style".我可以轻松地遍历所有底层数据存储元素,但我正在尝试定位特定的树节点,以便我可以使用“node.labelNode.style”设置它们的样式。
  • I could programmatically expand all of the dijit.tree nodes prior to calling getChildren() but I wish to preserve the user's view of the dijit.tree.我可以在调用 getChildren() 之前以编程方式扩展所有 dijit.tree 节点,但我希望保留用户对 dijit.tree 的视图。

Any suggestions are greatly appreciated.任何建议都非常感谢。

I'm not sure if this is what you are after, but that's how we are expanding all the nodes, which is similar to your task, getting all the nodes from the tree.我不确定这是否是您所追求的,但这就是我们扩展所有节点的方式,这与您的任务类似,从树中获取所有节点。 I believe with a simple modification you will be able to achieve your task我相信通过简单的修改,您将能够完成您的任务

Assume that we have a function for expanding the tree nodes, which we are going to call假设我们有一个扩展树节点的函数,我们将调用它

    this._expandTree(this._tree.rootNode);

and the function itself和函数本身

    _expandTree: function (node) {
                if (node.hasChildren()) {
                    var currentNode;
                    for (var i = 0; i < node.getChildren().length; i++) {
                        currentNode = node.getChildren()[i];                            
                        this._expandTree(currentNode);
                    }
                }
            },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM