Moe
Moe

Reputation: 31

Reloading a jstree without refreshing the page

I'm trying to reload a jstree without reloading or refreshing the page, the reload should happen onclick of a button, so when the button is clicked im calling

$("#tree-container").jstree('destroy'); 
//then calling the function that reads or renders the tree

that works fine when no tree is already rendered, however when a tree is already rendered and I click on the button I get this : "cannot call method init of undefined." the error occurs in the jstree plugin.

I even tried removing the container then re-appending it to it's parent container before calling the function that reads the tree

$("#tree-container").remove();

$('#parent-tree-container').append($('<div id="tree-container"></div>'));
//then called the function that reads/renders the tree  

but that still didn't work. :(

Thanks in advance.

Upvotes: 3

Views: 8743

Answers (2)

ChrisA
ChrisA

Reputation: 2101

Are you using jQuery 1.6.2? If so, try a lower version - 1.6.1 should work. - see here

Upvotes: 0

Bob
Bob

Reputation: 3084

This will make an ajax call to refresh the tree, but not the page it's contained in:

$.jstree._reference($("#tree-container")).refresh(-1);

That is the best method, but if you prefer, you can just rebuild the jstree over the initial div without destroying it first:

$("#tree-container").jstree({ etc

Upvotes: 5

Related Questions