Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  16] [ 5]  / answers: 1 / hits: 17881  / 13 Years ago, wed, march 23, 2011, 12:00:00

I would like to know how ot update the data of the dojo.dijit.tree component dynamically. At the moment I'm creating the tree using dojo.data.ItemFileReadStore and dijit.tree.ForestStoreModel. Once I create the tree, I would like to reload it periodically with new JSON data.



This is how I create the tree at the moment:



<div dojoType=dojo.data.ItemFileReadStore jsId=myStore url=getJSONResult></div>

<div dojoType=dijit.tree.ForestStoreModel jsId=myModel store=myStore query={type:'cat'} rootId=myRoot rootLabel=Data childrenAttrs=children></div>

<div dojoType=dijit.Tree model=myModel labelAttr=sname label=Data />


Thanks in advance.


More From » dojo

 Answers
20

Explicitly you can't, but that doesn't mean you can't hack things to pieces and die trying.



refreshTree : function(){
dijit.byId(myTree).dndController.selectNone(); // As per the answer below
// Credit to this discussion: http://mail.dojotoolkit.org/pipermail/dojo-interest/2010-April/045180.html
// Close the store (So that the store will do a new fetch()).
dijit.byId(myTree).model.store.clearOnClose = true;
dijit.byId(myTree).model.store.close();

// Completely delete every node from the dijit.Tree
dijit.byId(myTree)._itemNodesMap = {};
dijit.byId(myTree).rootNode.state = UNCHECKED;
dijit.byId(myTree).model.root.children = null;

// Destroy the widget
dijit.byId(myTree).rootNode.destroyRecursive();

// Recreate the model, (with the model again)
dijit.byId(myTree).model.constructor(dijit.byId(myTree).model)

// Rebuild the tree
dijit.byId(myTree).postMixInProperties();
dijit.byId(myTree)._load();

},


This will refresh your Tree.


[#93115] Tuesday, March 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaceyr

Total Points: 510
Total Questions: 97
Total Answers: 116

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
kaceyr questions
;