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

标签 jquery ajax jstree

我创建了一个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/

相关文章:

python - 当客户端过早断开连接时,如何对 Flask 上的破损管道错误进行异常(exception)处理?

javascript - jstree 检测多个项目被移动

php - 添加多个规范而不先保存

javascript - 记住下拉列表中最后选择的选项

jQuery 自定义事件

javascript - 在chrome扩展中使用ajax查询

java - java中如何防止刷新后重新提交

javascript - 在原始 JavaScript 中加载 ajax 后将事件(使用动态数据)绑定(bind)到元素的最佳方法

jquery - 如何刷新 jsTree 的内容?

javascript - JSTree - 禁用父节点上的选择,但允许单击扩展