JSTree: Make node expand when single clicked instead of double click?

sending this into the tree creation function did the trick:

   onselect: function(n, t) {
         t.toggle_branch(n);
    },

(where t is the reference to the tree)


$("#tree").bind("select_node.jstree", function (e, data) {
 $("#tree").jstree("toggle_node", data.rslt.obj);
 $("#tree").jstree("deselect_node", data.rslt.obj);
});

This might get you started in the right direction. You'll probably need to filter out which ones to expand or not depending on meta data.


I found the correct answer in an issue for the plugin on github. The above answers do NOT work. This absolutely works and is a comprehensive answer on how to call the plugin, and how to make it use single-click expand instead of double-click.

    $('#jstree')
        .on('click', '.jstree-anchor', function (e) {
            $(this).jstree(true).toggle_node(e.target);
        })
        .jstree()

Here is a link to where the author mentions the solution, in case you need it.

Tags:

Jstree