JSTree - How to force user tp only select leafs of the tree

自作多情 提交于 2019-12-23 10:06:44

问题


Within my JStree i want the user to only be able to select leafs of the tree. E.g.: Nodes that have no childs. My idea is to bind the select event and manually check whether the selected node has childs and then select/not select the node accordingly.

Is there a simpler way? or is this obvious solution the only one?


回答1:


You can use

  • Types plugin
  • .is_leaf() for checking if the selected node is a child- node (leaf) or not. Returning false in 'before'-Event will reject selecting the node. See the jsTree groups

In the code.

$('#treeID') 
.bind('before.jstree', function(event, data){ 
        switch(data.plugin){ 
                case 'ui': 
                        if(data.inst.is_leaf(data.args[0])){ 
                                return false; 
                        } 
                        break; 
                default: 
                        break; 
        } 
}) 



回答2:


2014 - version 3.0.1

$('#jstree').on('activate_node.jstree', function(e, data) {
  if(data.instance.is_leaf(data.node)) {
    ...
  }
});



回答3:


Simple Solution For Use CheckBox Plugin (To RadioButton Behavior) Is Here

$('#treeview').bind('activate_node.jstree', function (event, data) {
            if (data.instance.get_checked().length > 1) {
                data.instance.uncheck_all();
            }
        });

In this jquery.



来源:https://stackoverflow.com/questions/8502697/jstree-how-to-force-user-tp-only-select-leafs-of-the-tree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!