When I do the following
$('#tree').dynatree("option","initAjax",{url:"http://google.com"});
I want dynatree to forget about current tree data and reload with new data from the specified url instead. But I find it does not do that by default.
Thanks.
Function the initialization:
To reload data, call:
if You Want To Reload the Dynatree Means First Remove the node By he below code
$("#tree").dynatree("getRoot").removeChildren();
look at the
tree.reload()
method, it should do what you are after.see the docs here: http://wwwendt.de/tech/dynatree/doc/dynatree-doc.html#h8.2
as in the docs, the tree is the internal drawing of the tree, and you get it by calling the getTree command:
$("#node").dynatree("getTree")
Initially, i was using the "options" with initAjax to make the ajax call. However, since i had to show an error message incase there was an empty response from the server after the reload, i decided to go the usual ajax route. I make the ajax call, get the response and then reload the tree. So i did it like this in my javascript file
Calling function
The dynatree was initialized in a seperate javascript file
This question is a duplicate of Trying to reload/refresh dynatree with new data
My solution does not require detours like
empty()
anddestroy()
etc. Think about this: When the Dynatree is created you specify a dictionary of settings it must use. However as this is a configuration dictionary it will not be reevaluated even though some parameters are variables and change due to clicks etc. So to solve this and avoid expensive operations like deleting the DOM and recreating it we do it the way I think the Dynatree developers has this intended (but not so clearly documented in the AJAX/JSON example):This example sets the configuration on the
#tree
every time the button is clicked, then reloads the tree.