title: Expanding all nodes in dijit.Tree
body: <p>Is there a good way to expand/close all the expandable nodes in a <code>dijit.Tree</code>?</p>
  
  <p>For those looking for an answer, put this in your initializing code:</p>
  
  <pre><code>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);
      }
  });
  </code></pre>
  
  <p>At least, that works for me. And you can do the same with <code>collapseAll()</code> where you only need to switch <code>_this._expandNode(node);</code> with <code>_this._collapseNode(node);</code></p>