javascript - Expand jsTree node when parent is clicked -


i trying implement simple tree using jstree. have found documentation dense , overwhelming.

right now, expand / collapse node clicking arrow shown here:

enter image description here

i want able expand / collapse clicking node name too:

enter image description here

the code using simple; have not altered javascript jstree:

<ul id="tree">    <li>       subfolder1       <ul id="tree">          <li data-jstree='{"icon":"/images/blue-folder.png"}'>pub 1</li>       </ul>    </li> </ul> 

just add event listener in html file , call toggle_node function. code below listens single click.

$(document).ready(function(){   $('#jstree_div').on("select_node.jstree", function (e, data) { $('#jstree_div').toggle_node(data.node); }); } 

if want listen double click need event listener, since jstree not support double click events yet.

$('#jstree_div').on("dblclick",function (e) {    var li = $(e.target).closest("li");   var node = $('#jstree_div').get_node(li[0].id);    $('#jstree_div').toggle_node(node) }); 

hope helps.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -