javascript to expand all parents of checked nodes?

90 views
Skip to first unread message

Chris

unread,
Oct 21, 2015, 9:46:52 AM10/21/15
to jsTree
Trying to create a button that will expand to show all of the checked nodes in the tree...

I can grab a list of all of those nodes, and I think i need to invoke open_node on them but I'm not sure how to do it..

var checkedNodes = $('#jstree').jstree("get_checked", true);


Chris

unread,
Oct 21, 2015, 1:46:32 PM10/21/15
to jsTree
I went with this.  It uses the side effect of opening the node up to the parent, but I didn't like the additional side effect of selecting the node, so it also handles deselecting it if it wasn't already selected.

$('#toggleSelectedButton').click(function () {
        var checkedNodes = $('#jstree').jstree("get_checked", true);
        $.each(checkedNodes, function (index, value) {
            var isSelected = $('#jstree').jstree('is_selected', value);
            $('#jstree').jstree('select_node', value);
            if (!isSelected) {
                $('#jstree').jstree('deselect_node', value);
            }
        });
    });
Reply all
Reply to author
Forward
0 new messages