vakata / jstree

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

Disable all leaf in shortend way #2593

Closed unusualious closed 2 years ago

unusualious commented 2 years ago

Hello Guys, I wanna set access for users in limited situations. Users but can only check leaf in JSTREE and in this way I tried multi ways but never get the correct results. I think this(Bellow Codes) way can solve this problem but I can't get good results yet.

          if (!data.instance.is_leaf(data.node)) {
               console.log("for leafs :::: "+data);
                $("#jstree").jstree().disable_node(data.node);   
                }
vakata commented 2 years ago

The only shorthand way I can think of right now is to iterate through the internal node storage (_data.model) and check for nodes which are loaded, but their children array has a zero length. You can then set the disabled property directly in the node object and once done - redraw the tree. But this makes sense only in huge trees.