我创建了一个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 方法从所选节点中过滤我们唯一的叶节点?
我参考了这篇文章——强制用户仅选择叶节点 https://stackoverflow.com/questions/8502697/jstree-how-to-force-user-tp-only-select-leafs-of-the-tree这个解决方案对我不起作用。
我自己使用论证找到了一个解决方案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");
}
});
如果您有更好的解决方案请告诉我。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)