JSTree - 如何强制用户tp只选择树的叶子 [英] JSTree - How to force user tp only select leafs of the tree
本文介绍了JSTree - 如何强制用户tp只选择树的叶子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的JStree中,我希望用户只能选择树的叶子。例如:没有孩子的节点。我的想法是绑定select事件并手动检查所选节点是否有子节点,然后选择/不选择相应的节点。
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?
推荐答案
你可以使用
- 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
代码中。
$('#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;
}
})
这篇关于JSTree - 如何强制用户tp只选择树的叶子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文