mercredi 22 novembre 2017

How to keep jsTree from opening nodes marked as 'selected' in JSON

I am building a jsTree with check boxes, which will be checked or unchecked via an AJAX call. But before getting the AJAX up and running, I decided to experiment with hard-coded JSON data in my HTML. This shows that every node with children is automatically opened when I set its property 'selected' to true, no matter if I set its 'opened' property to false. Here is the code I am using to test this feature:

    $(function () {
    $('#json').jstree(
    {
        "core" : 
            { 'data' : [
                   'Simple root node',
                   { 'text'  : 'Root node 2',
                     'state' : { 'opened' : false,
                                'selected' : true },
                     'children' : [
                        { 'text' : 'Child 1' },
                        { 'text' : 'Child 2' }
                     ]
                  }
                ]
            },
            "checkbox" : { "keep_selected_style" : false },
            "plugins"  : [ "checkbox" ]
        }
    );
});

When I change the 'selected' property of Root node 2 to false, the tree shows that node collapsed, as expected. I have tried a property 'checked' instead but that is not recognized.

Once the tree is shown, I can check child nodes and then collapse the parent, or check and uncheck the parent without expanding it. That is what I was also expecting to get by initialising the jsTree with JSON as in my example above.

Is this a known bug or limitation on jsTree? Does this behaviour depend on the version of jsTree? I am using jsTree v 3.3.3 with jQuery 1.11.1. I am not getting any errors in my console that point out an unsupported feature or failing dependency.




Aucun commentaire:

Enregistrer un commentaire