gpt4 book ai didi

jquery - JSTree 检查所选节点是否为叶子或仅叶子可选

转载 作者:行者123 更新时间:2023-12-01 01:06:48 25 4
gpt4 key购买 nike

我创建了一个jstree,如下

$('#js-tree').jstree({
'core' : {
'data' : {
'url' : "${pageContext.request.contextPath}/makeTree",
"plugins" : [ "types", "search"],
'data' : function (node) {
return { 'id' : node.id };
}
}
}
});

我想在提交信息时检查所选节点是否是叶节点 -

var selectedLeaves = $("#js-tree").jstree("get_selected");

但这只给了我 id 数组。如何使用 is_leaf 方法从所选节点中过滤我们唯一的叶节点?我引用了这篇文章—— Force user to select only leaf nodes这个解决方案对我来说不起作用。

最佳答案

我自己找到了一个解决方案,使用 get_selected api 的参数来过滤掉文件夹中的叶子 -

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");
}
});

如果您有更好的解决方案,请告诉我。

关于jquery - JSTree 检查所选节点是否为叶子或仅叶子可选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31304533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com