Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 737
John Doe Avatar asked Jun 23 '11 09:06

John Doe


2 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);
like image 161
dead10ck Avatar answered Nov 10 '22 17:11

dead10ck


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!

like image 1
apfz Avatar answered Nov 10 '22 17:11

apfz