dijit._TreeNode.setChildItems
dojo.require("dijit.Tree");
defined in dijit/Tree.js
Sets the child items of this node, removing/adding nodes from current children to match specified items[] array.
Usage
function (items) (view source)
var tree = this.tree, model = tree.model; // Orphan all my existing children. // If items contains some of the same items as before then we will reattach them. // Don't call this.removeChild() because that will collapse the tree etc. this.getChildren().forEach(function(child){ dijit._Container.prototype.removeChild.call(this, child); }, this); this.state = "LOADED"; if(items && items.length > 0){ this.isExpandable = true; if(!this.containerNode){ // maybe this node was unfolderized and still has container this.containerNode = this.tree.containerNodeTemplate.cloneNode(true); this.domNode.appendChild(this.containerNode); } // Create _TreeNode widget for each specified tree node, unless one already // exists and isn't being used (presumably it's from a DnD move and was recently // released dojo.forEach(items, function(item){ var id = model.getIdentity(item), existingNode = tree._itemNodeMap[id], node = ( existingNode && !existingNode.getParent() ) ? existingNode : new dijit._TreeNode({ item: item, tree: tree, isExpandable: model.mayHaveChildren(item), label: tree.getLabel(item) }); this.addChild(node); // note: this won't work if there are two nodes for one item (multi-parented items); will be fixed later tree._itemNodeMap[id] = node; if(this.tree.persist){ if(tree._openedItemIds[id]){ tree._expandNode(node); } } }, this); // note that updateLayout() needs to be called on each child after // _all_ the children exist dojo.forEach(this.getChildren(), function(child, idx){ child._updateLayout(); }); }else{ this.isExpandable=false; } if(this._setExpando){ // change expando to/from dot or + icon, as appropriate this._setExpando(false); } // On initial tree show, put focus on either the root node of the tree, // or the first child, if the root node is hidden if(!this.parent){ var fc = this.tree.showRoot ? this : this.getChildren()[0], tabnode = fc ? fc.labelNode : this.domNode; tabnode.setAttribute("tabIndex", "0"); } // create animations for showing/hiding the children (if children exist) if(this.containerNode && !this._wipeIn){ this._wipeIn = dojo.fx.wipeIn({node: this.containerNode, duration: 150}); this._wipeOut = dojo.fx.wipeOut({node: this.containerNode, duration: 150}); }
parameter | type | description |
---|---|---|
items |