How to get checked nodes in jquery jstree

后端 未结 5 1512
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 21:09

I have created one jquery jstree and it\'s working fine. Now the problem is how to get the the checked nodes details.

For Creating JStree The code is:

相关标签:
5条回答
  • 2020-12-19 22:00
      function submitMe(){ 
            var checked_ids = []; 
            $("#server_tree").jstree("get_checked",null,true).each 
                (function () { 
                    checked_ids.push(this.id); 
                }); 
               doStuff(checked_ids); 
    

    Go through this once jstree google groups

    0 讨论(0)
  • 2020-12-19 22:07
    $.each($("#jstree_demo_div").jstree("get_checked",true),function(){alert(this.id);});
    
    0 讨论(0)
  • 2020-12-19 22:08

    While using get_checked or get_selected pass the boolean as false to get the whole node where if you send as true, it will return only node Ids.

    You have a look at https://www.jstree.com/api/#/?q=checkbox&f=get_checked([full])

    You can also have a look at https://everyething.com/Example-of-jsTree-to-get-all-checked-nodes to get an idea of different kind of selected.

    0 讨论(0)
  • 2020-12-19 22:10
    $('#dvTreeStructure').on('changed.jstree', function (e, data) {
                    var i, j, r = [];
                    for (i = 0, j = data.selected.length; i < j; i++) {
                        r.push(data.instance.get_node(data.selected[i]).text.trim());
                    }
                    alert('Selected: ' + r.join(', '));
    
                }
    
    0 讨论(0)
  • 2020-12-19 22:12

    As the Author of jstree (Ivan Bozhanov) points out on google-Groups Discussion regarding get_checked, it can also be achieved using the following:

    $('#tree').jstree(true).get_selected();
    

    This returns a List of the IDs, e.g. ["j1_2"] or ["j1_2", "j1_3", "j1_1"]

    Check out the fiddle by Ivan Bozhanov himself on: jsfiddle-Example get_selected

    0 讨论(0)
提交回复
热议问题