1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.Tree-method-constructor'><span id='Ext-data.Tree'>/**
2 </span></span> * @class Ext.data.Tree
4 * This class is used as a container for a series of nodes. The nodes themselves maintain
5 * the relationship between parent/child. The tree itself acts as a manager. It gives functionality
6 * to retrieve a node by its identifier: {@link #getNodeById}.
8 * The tree also relays events from any of it's child nodes, allowing them to be handled in a
9 * centralized fashion. In general this class is not used directly, rather used internally
10 * by other parts of the framework.
13 * @param {Node} root (optional) The root node
15 Ext.define('Ext.data.Tree', {
19 observable: "Ext.util.Observable"
22 <span id='Ext-data.Tree-property-root'> /**
23 </span> * The root node for this tree
28 constructor: function(root) {
33 me.mixins.observable.constructor.call(me);
40 <span id='Ext-data.Tree-method-getRootNode'> /**
41 </span> * Returns the root node for this tree.
42 * @return {Ext.data.NodeInterface}
44 getRootNode : function() {
48 <span id='Ext-data.Tree-method-setRootNode'> /**
49 </span> * Sets the root node for this tree.
50 * @param {Ext.data.NodeInterface} node
51 * @return {Ext.data.NodeInterface} The root node
53 setRootNode : function(node) {
57 Ext.data.NodeInterface.decorate(node);
59 if (me.fireEvent('beforeappend', null, node) !== false) {
60 node.set('root', true);
63 me.relayEvents(node, [
64 <span id='Ext-data.Tree-event-append'> /**
65 </span> * @event append
66 * Fires when a new child node is appended to a node in this tree.
67 * @param {Tree} tree The owner tree
68 * @param {Node} parent The parent node
69 * @param {Node} node The newly appended node
70 * @param {Number} index The index of the newly appended node
74 <span id='Ext-data.Tree-event-remove'> /**
75 </span> * @event remove
76 * Fires when a child node is removed from a node in this tree.
77 * @param {Tree} tree The owner tree
78 * @param {Node} parent The parent node
79 * @param {Node} node The child node removed
83 <span id='Ext-data.Tree-event-move'> /**
85 * Fires when a node is moved to a new location in the tree
86 * @param {Tree} tree The owner tree
87 * @param {Node} node The node moved
88 * @param {Node} oldParent The old parent of this node
89 * @param {Node} newParent The new parent of this node
90 * @param {Number} index The index it was moved to
94 <span id='Ext-data.Tree-event-insert'> /**
95 </span> * @event insert
96 * Fires when a new child node is inserted in a node in this tree.
97 * @param {Tree} tree The owner tree
98 * @param {Node} parent The parent node
99 * @param {Node} node The child node inserted
100 * @param {Node} refNode The child node the node was inserted before
104 <span id='Ext-data.Tree-event-beforeappend'> /**
105 </span> * @event beforeappend
106 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
107 * @param {Tree} tree The owner tree
108 * @param {Node} parent The parent node
109 * @param {Node} node The child node to be appended
111 "beforeappend",
113 <span id='Ext-data.Tree-event-beforeremove'> /**
114 </span> * @event beforeremove
115 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
116 * @param {Tree} tree The owner tree
117 * @param {Node} parent The parent node
118 * @param {Node} node The child node to be removed
120 "beforeremove",
122 <span id='Ext-data.Tree-event-beforemove'> /**
123 </span> * @event beforemove
124 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
125 * @param {Tree} tree The owner tree
126 * @param {Node} node The node being moved
127 * @param {Node} oldParent The parent of the node
128 * @param {Node} newParent The new parent the node is moving to
129 * @param {Number} index The index it is being moved to
131 "beforemove",
133 <span id='Ext-data.Tree-event-beforeinsert'> /**
134 </span> * @event beforeinsert
135 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
136 * @param {Tree} tree The owner tree
137 * @param {Node} parent The parent node
138 * @param {Node} node The child node to be inserted
139 * @param {Node} refNode The child node the node is being inserted before
141 "beforeinsert",
143 <span id='Ext-data.Tree-event-expand'> /**
144 </span> * @event expand
145 * Fires when this node is expanded.
146 * @param {Node} this The expanding node
150 <span id='Ext-data.Tree-event-collapse'> /**
151 </span> * @event collapse
152 * Fires when this node is collapsed.
153 * @param {Node} this The collapsing node
155 "collapse",
157 <span id='Ext-data.Tree-event-beforeexpand'> /**
158 </span> * @event beforeexpand
159 * Fires before this node is expanded.
160 * @param {Node} this The expanding node
162 "beforeexpand",
164 <span id='Ext-data.Tree-event-beforecollapse'> /**
165 </span> * @event beforecollapse
166 * Fires before this node is collapsed.
167 * @param {Node} this The collapsing node
169 "beforecollapse" ,
171 <span id='Ext-data.Tree-event-rootchange'> /**
172 </span> * @event rootchange
173 * Fires whenever the root node is changed in the tree.
174 * @param {Ext.data.Model} root The new root
176 "rootchange"
181 insert: me.onNodeInsert,
182 append: me.onNodeAppend,
183 remove: me.onNodeRemove
186 me.registerNode(node);
187 me.fireEvent('append', null, node);
188 me.fireEvent('rootchange', node);
194 <span id='Ext-data.Tree-method-flatten'> /**
195 </span> * Flattens all the nodes in the tree into an array.
197 * @return {Array} The flattened nodes.
201 hash = this.nodeHash,
205 if (hash.hasOwnProperty(key)) {
206 nodes.push(hash[key]);
212 <span id='Ext-data.Tree-method-onNodeInsert'> /**
213 </span> * Fired when a node is inserted into the root or one of it's children
215 * @param {Ext.data.NodeInterface} parent The parent node
216 * @param {Ext.data.NodeInterface} node The inserted node
218 onNodeInsert: function(parent, node) {
219 this.registerNode(node);
222 <span id='Ext-data.Tree-method-onNodeAppend'> /**
223 </span> * Fired when a node is appended into the root or one of it's children
225 * @param {Ext.data.NodeInterface} parent The parent node
226 * @param {Ext.data.NodeInterface} node The appended node
228 onNodeAppend: function(parent, node) {
229 this.registerNode(node);
232 <span id='Ext-data.Tree-method-onNodeRemove'> /**
233 </span> * Fired when a node is removed from the root or one of it's children
235 * @param {Ext.data.NodeInterface} parent The parent node
236 * @param {Ext.data.NodeInterface} node The removed node
238 onNodeRemove: function(parent, node) {
239 this.unregisterNode(node);
242 <span id='Ext-data.Tree-method-getNodeById'> /**
243 </span> * Gets a node in this tree by its id.
245 * @return {Ext.data.NodeInterface} The match node.
247 getNodeById : function(id) {
248 return this.nodeHash[id];
251 <span id='Ext-data.Tree-method-registerNode'> /**
252 </span> * Registers a node with the tree
254 * @param {Ext.data.NodeInterface} The node to register
256 registerNode : function(node) {
257 this.nodeHash[node.getId() || node.internalId] = node;
260 <span id='Ext-data.Tree-method-unregisterNode'> /**
261 </span> * Unregisters a node with the tree
263 * @param {Ext.data.NodeInterface} The node to unregister
265 unregisterNode : function(node) {
266 delete this.nodeHash[node.getId() || node.internalId];
269 <span id='Ext-data.Tree-method-sort'> /**
270 </span> * Sorts this tree
272 * @param {Function} sorterFn The function to use for sorting
273 * @param {Boolean} recursive True to perform recursive sorting
275 sort: function(sorterFn, recursive) {
276 this.getRootNode().sort(sorterFn, recursive);
279 <span id='Ext-data.Tree-method-filter'> /**
280 </span> * Filters this tree
282 * @param {Function} sorterFn The function to use for filtering
283 * @param {Boolean} recursive True to perform recursive filtering
285 filter: function(filters, recursive) {
286 this.getRootNode().filter(filters, recursive);
288 });</pre></pre></body></html>