treejs
treejs copied to clipboard
Collapse all on load and then collapse level-by-level
closeDepth: 1 will help me to only show the first level of the tree with all collapsed.
If I click on an item it will open, but it opens all childrens not only the next level/children. How can I prevent this?
I solved this issue by using the collapseAll() function in the built-in loaded function:
let newTree = function(data){ let tree = new Tree('.container', { data: data, closeDepth: 1, loaded: function () { this.collapseAll() }, onChange: function () { } }) }
`function preventChildExpansion() {
$('.treejs-switcher').each(function () {
var $parent = $(this).closest('.treejs-node');
if (!$parent.hasClass('treejs-node__close')) {
$parent.addClass('treejs-node__close');
}
});
}`
Then, when tree is loaded :
loaded: function () { preventChildExpansion(); }