简体   繁体   中英

How to use checkbox checked, unchecked & select_node event separately

I am using JSTree & working on a scenario in which I have to perform different actions on the checked, unchecked and select event of node. "select_node" works fines as I only need the node details there but I need PROPER list of checked nodes on check_node & uncheck_node events.

check_node The "data.selected.length" return 1 if root along with all its is child are selected, But I want full list.

uncheck_node Unchecking the root return the length of checked nodes before unchecking the nodes Here my need is to get the length of checked nodes after uncheck them

<a href="http://jsfiddle.net/mL7bna1p/">Code on JSFiddle</a>

I think a different function will solve your problems here. Use the get_checked function instead of get_selected:

$('#jstree').on("check_node.jstree", function (e, data) 
{
   //var selectedNode = $(jstree).jstree().get_selected(true);
   var selectedNodes = $(jstree).jstree().get_checked();
   alert("Checked: "+ selectedNodes.length);
});

$('#jstree').on("uncheck_node.jstree", function (e, data) 
{
   //var selectedNode= $('#jstree').jstree(true).get_selected('full',true);
   var selectedNodes = $(jstree).jstree().get_checked();
   alert("Checked: "+ selectedNodes.length);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM