How do I bind a callback function on the complete jstree reload event?

I have a button that reloads (resends an AJAX request) the jsTree once is clicked.

Here is a sample configuration code I have:

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

The problem I experience is that I do not have the alert (wrapped in a callback function) displayed once the 'reload' button is clicked the 2nd, 3rd, etc. times. Am I using the wrong jstree status event?

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

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

Answers


Destroying the tree before building the new one works as well.

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

add this to the core:

        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 allready existing reopen-method. now create the 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 carefull, because this alert-message will also be called when the tree is done loading. It is anyhow better, since you now have a way to have a callback when the tree is refreshed!

hope this helps you all!


From the jstree documentation:

.loaded ()

A dummy function, whose purpose is only to trigger the loaded event. This event is triggered once after the tree's root nodes are loaded, but before any nodes set in initially_open are opened.

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

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

See also the "Interacting with the tree" section on the same jstree documentation page.


Need Your Help

MySQL collation error

php mysql character-encoding laravel

I have the following query. It works fine if I execute it in MySQL. But when I call it from my PHP program it give me this error:

Why should url-pattern in servlet mapping start with forward slash(/)

java servlets url-pattern servlet-mapping

I was reading Head First JSP and Servlets book. I was going through the mapping of servlet. And my doubt here is

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.