1

I am using jsTree 3.3.1 and the following image is the tree generated. Now you can see i have selected D and E, then its parents(B and C ) also selected. I would like to get the selected parents(B and C) id along with the childs(D and E). I have used the following function and it not working for me. Also i have found this url which is not working for me. Any help really appreciated.

Image

var arr = new Array();
$("#testtree").jstree('get_checked').each(function(index) {
arr.push($(this).attr('id'));
});
Community
  • 1
  • 1
prinz
  • 148
  • 10

1 Answers1

1

The result returned by get_checked is a plain array of ids, while you are trying to iterate it as a jQuery collection. Also you will need to grab id's of parents with undetermined status. So you could use code as below. Also check demo - Fiddle Demo

  var arr = $("#testtree").jstree('get_checked');

  $("#testtree").find(".jstree-undetermined").each(
    function(i, element) {
        arr.push( $(element).closest('.jstree-node').attr("id") );
    }
); 
Nikolay Ermakov
  • 5,031
  • 2
  • 11
  • 18