How to bind callback function in whole jstree reload event?

I have a button that reloads (redirects an AJAX request), jsTree is pressed.

Here is an example configuration code that I have:

treeContainer.bind("loaded.jstree", function () { alert("the tree is loaded"); }).jstree(config); 

The problem I am experiencing is that I do not have a warning (wrapped in a callback function) displayed after pressing the reset button of the 2nd, 3rd, etc. Am I using the wrong jstree event event?

To summarize, I want the jsTree callback function to be executed every time I click the reload button.

I am currently using jsTree 1.0-rc1 (rev. 191) .

+6
source share
3 answers

Destroying a tree before creating a new one also works.

 treeContainer.jstree("destroy"); treeContainer.bind("loaded.jstree", function () { alert("the tree is loaded"); }).jstree(config); 
+5
source

add this to the kernel:

  reopen : function () { var _this = this; if(this.data.core.to_open.length) { $.each(this.data.core.to_open, function (i, val) { _this.open_node(val, false, true); }); } this.__callback({}); this.reopened(); }, 

note that only this .reopened is added to the existing reopen method. now create a reopened method:

  reopened : function () { this.__callback(); }, 

now bind the new reopened method to your tree selector

 }).bind("reopened.jstree", function (e,data) { alert("i am refreshed..."); }); 

be careful because this warning message will also be called when the tree is loaded. This is somehow better, since now you have a way to have a callback when the tree is updated!

Hope this helps you all!

+1
source

From the jstree documentation :

.loaded ()

A dummy function whose purpose is to only trigger a loaded event. This event is fired once after the nodes of the tree root are loaded, but before any nodes set in initial_open are opened.

So you can call this method from the success callback of your ajax call. Something like that:

 $.ajax({ url: "yourscript-url", success: function(){ $('selector-for-jstree-container').jstree('loaded'); } }); 

See also the “ Tree Interaction ” section on the same jstree documentation page.

-1
source

Source: https://habr.com/ru/post/891199/


All Articles