Skip to content

Instantly share code, notes, and snippets.

@alanland
Created August 23, 2013 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanland/6315636 to your computer and use it in GitHub Desktop.
Save alanland/6315636 to your computer and use it in GitHub Desktop.
Dojo Tree.refresh
require(["dojo/_base/lang", "dijit/Tree"], function(lang, Tree){
lang.extend(Tree, {
refresh : function() {
// Destruct the references to any selected nodes so that
// the refreshed tree will not attempt to unselect destructed nodes
// when a new selection is made.
// These references are contained in Tree.selectedItem,
// Tree.selectedItems, Tree.selectedNode, and Tree.selectedNodes.
this.dndController.selectNone();
this.model.store.clearOnClose = true;
//this.model.store.close();
// Completely delete every node from the dijit.Tree
this._itemNodesMap = {};
this.rootNode.state = "UNCHECKED";
this.model.root.children = null;
// Destroy the widget
this.rootNode.destroyRecursive();
// Recreate the model, (with the model again)
this.model.constructor(dijit.byId("myTree").model)
// Rebuild the tree
this.postMixInProperties();
this._load();
}
});
});
// then you can call
tree.refresh();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment