mercredi 23 mars 2016

Jstree - Can't check checkboxes in AJAX call, works in classic call. An issue?

I do an AJAX call for creating and populating my JSTree div. I activated the checkbox plugin and try to check all checkboxes within my AJAX result callback. It doesn't work.

I binded the same function (that will check all boxes) to a button and, here, it works.

I also tried to check all checkboxes through a custom event with jQuery but it doesn't do anything, as in the AJAX call

Is this an issue with JSTree or is there something that I'm missing?

I reproduced this issue (?) in JsFiddle: http://ift.tt/1RhKOtI


Specs:

  • jQuery 1.9.1
  • jsTree 3.2.1

The code

HTML

<h1>
JSTree Demo
</h1>
<button id="btn">
Check All
</button>
<div id="jstree">

</div>

JS

// Populate the tree with some generic data
$.ajax({
    // ... initial ajax code with some generic data
    success: function(response) {
            var $tree = $("#jstree");
            $tree.jstree(response);

        // Try to check all boxes, it doesn't work
        checkAll($tree);
    }
});

// Try to check all boxes, here it works. Why.
$("#btn").click(function(){
        checkAll($("#jstree"));
})

// This will check all boxes inside the tree
function checkAll(tree) {
        tree.jstree(true).check_all();
}




Aucun commentaire:

Enregistrer un commentaire