Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The refreshing of a <code>dijit.Tree</code> becomes a little more complicated, since there is a model involved (which in grid afaik is inbuilt, the grid component implements query functionality)</p> <h3>Performing search via store</h3> <p>But how to search, thats incredibly easy whilst using the <code>ItemFileReadStore</code>. Syntax is as such:</p> <pre><code>myTree.model.store.fetch({ query: { name: 'Oranges' }, onComplete: function(items) { dojo.forEach(items, function(item) { console.log(myTree.model.store.getValue(item, "ID")); }); } }); </code></pre> <h3>Displaying search results only</h3> <p>As shown above, the store will fetch, the full payload is put into its _allItemsArray and the store queryengine then filters out what its told by query argument to the fetch method. At any time, we could call fetch on store, even without sending an XHR for json contents - fetch with query argument can be considered as a simple filter.</p> <p>It becomes slightly more interesting to let the <code>Model</code> know about this query.. If you do so, it will only create <code>treeNode</code>s to fill the tree, based on the returned results from <code>store.fetch({query:model.query});</code></p> <p>So, instead of sending store.fetch with a callback, lets _try to set model query and update the tree.</p> <pre><code>// seing as we are working with a multi-parent tree model (ForestTree), the query Must match a toplevel item or else nothing is shown myTree.model.query = { name:'Fruits' }; // below method must be implemented to do so runtime // and note, that the DnD might become invalid myTree.update(); </code></pre> <h3>Refreshing tree with new xhr-request from store</h3> <p>You need to do exactly as you do with regards to the store. Close it but then rebuild the model. Model contains all the <code>TreeNode</code>s (beneath its root-node) and the <code>Tree</code> itself maps an itemarray which needs to be cleared to avoid memory leakage.</p> <p>So, performing following steps will rebuild the tree - however this sample does not take in account, if you have DnD activated, the dndSource/dndContainer will still reference the old DOM and thereby 'keep-alive' the previous DOMNode hierachy (hidden ofc).</p> <p>By telling the model that its rootNode is <code>UNCHECKED</code>, the children of it will be checked for changes. This in turn will produce the subhierachy once the tree has done its <code>_load()</code></p> <p>Close the store (So that the store will do a new fetch()).</p> <pre><code> this.model.store.clearOnClose = true; this.model.store.close(); </code></pre> <p>Completely delete every node from the dijit.Tree</p> <pre><code> delete this._itemNodesMap; this._itemNodesMap = {}; this.rootNode.state = "UNCHECKED"; delete this.model.root.children; this.model.root.children = null; </code></pre> <p>Destroy the widget</p> <pre><code> this.rootNode.destroyRecursive(); </code></pre> <p>Recreate the model, (with the model again)</p> <pre><code> this.model.constructor(this.model) </code></pre> <p>Rebuild the tree</p> <pre><code> this.postMixInProperties(); this._load(); </code></pre> <p><a href="http://mail.dojotoolkit.org/pipermail/dojo-interest/2010-April/045180.html" rel="nofollow">Creds</a>; All together as such, scoped onto the dijit.Tree:</p> <pre><code>new dijit.Tree({ // arguments ... // And additional functionality update : function() { this.model.store.clearOnClose = true; this.model.store.close(); delete this._itemNodesMap; this._itemNodesMap = {}; this.rootNode.state = "UNCHECKED"; delete this.model.root.children; this.model.root.children = null; this.rootNode.destroyRecursive(); this.model.constructor(this.model) this.postMixInProperties(); this._load(); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload