vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.13k stars 1.39k forks source link

can't make node.state work as expected #2777

Closed evinck closed 5 months ago

evinck commented 5 months ago

Hello, could you help me with this code extract below ?

Setting the state to { opened: true } does indeed open the tree, but using { opened: false} doesn't work (the tree stays opened)

Thanks,

var allNodes = $('#json-tree').jstree(true).get_json('#', { flat: true });

allNodes.forEach(function(node) {
    // expand all
    if (document.getElementById('allExpanded').checked)  {
             node.state = { opened: true };
    } else {
             console.log('debug 1');
             node.state = { opened : false};
    }                        
});

// Update jstree with the modified nodes
$('#json-tree').jstree(true).settings.core.data = allNodes;
$('#json-tree').jstree(true).refresh();
evinck commented 5 months ago

sorry wrong place for this