JSTree检查选择的节点是叶或作出只剩可选 [英] JSTree check is selected nodes are leaf or make only leaves selectable
问题描述
我创建了一个jstree如下:
I created a jstree as follows
$('#js-tree').jstree({
'core' : {
'data' : {
'url' : "${pageContext.request.contextPath}/makeTree",
"plugins" : [ "types", "search"],
'data' : function (node) {
return { 'id' : node.id };
}
}
}
});
我要检查,如果选择的节点是在提交信息的叶节点 -
I want to check if a selected node is a leaf node while submitting the information -
var selectedLeaves = $("#js-tree").jstree("get_selected");
但是,这给了我ID的唯一的数组。我怎么要么使用is_leaf方法从所选节点筛选我们唯一的叶节点? 我提到的这个帖子 - <一href="http://stackoverflow.com/questions/8502697/jstree-how-to-force-user-tp-only-select-leafs-of-the-tree">Force用户只选择叶节点 该解决方案并没有为我工作。
But this gives me array of id's only. How do I either use is_leaf method to filter our only leaf nodes from the selected nodes? I referred to this post - Force user to select only leaf nodes This solution did not work for me.
推荐答案
我发现用一个参数 get_selected
API来过滤掉叶子我自己的解决方案文件夹 -
I found a solution on my own using an argument to the get_selected
api to filter out the leaves from the folders -
var nodes = $("#js-tree").jstree(true).get_selected("full", true);
$.each(nodes,function(i, node){
if(node.children.length >0){
console.log("not leaf");
}
else{
console.log("leaf");
}
});
如果你有一个更好的解决方案,请让我知道。
If you have a better solution please let me know.
这篇关于JSTree检查选择的节点是叶或作出只剩可选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!