代码之家  ›  专栏  ›  技术社区  ›  peirix

展开dijit.tree中的所有节点

  •  4
  • peirix  · 技术社区  · 15 年前

    是否有一个好的方法来展开/关闭 dijit.Tree ?

    对于寻找答案的人,请将其放入初始化代码中:

    var treeControl = new dijit.Tree({
        model: treeModel,
        expandAll: function() {
            // summary:
            //     Expand all nodes in the tree
            // returns:
            //     Deferred that fires when all nodes have expanded
    
            var _this = this;
    
            function expand(node) {
                _this._expandNode(node);
    
                var childBranches = dojo.filter(node.getChildren() || [], function(node) {
                    return node.isExpandable;
                });
    
                var def = new dojo.Deferred();
                defs = dojo.map(childBranches, expand);
            }
            return expand(this.rootNode);
        }
    });
    

    至少,这对我有用。你也可以这么做 collapseAll() 你只需要换个地方 _this._expandNode(node); 具有 _this._collapseNode(node);

    3 回复  |  直到 10 年前
        1
  •  8
  •   Bill Keese    15 年前

    是,autoexpand=true(作为树的初始化参数)。

    如果您需要动态地展开/折叠,树以前有一个方法,但我把它去掉了。但是,您可以从以下位置复制: http://bugs.dojotoolkit.org/changeset/20529 .

        2
  •  2
  •   Matt X    14 年前

    折叠所有节点…(记住 不坍塌 未显示根节点时的根节点(我喜欢为我的树显示多个项)

    _collapseAllTreeNodeContainers: function(){ 
    
         var _tree = _this; 
    
            function collapse(node) {
       // never collapse root node, otherwise hides whole tree !
       if ( _tree.showRoot == false && node != _tree.rootNode ) {
        _tree._collapseNode(node);
       }
    
                var childBranches = dojo.filter(node.getChildren() || [], function(node) {
                    return node.isExpandable;
                });
    
                var def = new dojo.Deferred();
                defs = dojo.map(childBranches, collapse);
            }
            return collapse( _tree.rootNode);
        }
    
        3
  •  1
  •   GibboK    10 年前