javascript - 如何创建仅在叶节点上带有复选框的复选框树

标签 javascript jquery jquery-ui tree jstree

根据 jstree,默认情况下,所有节点包括父节点和子节点旁边都有复选框。

jstree

但我想要这样的东西jqueryeasyUI tree 其中有用于级联和叶节点检查的选项。

编辑: 下面给出了一个示例。

<div id="jstree">
    <!-- in this example the tree is populated from inline HTML -->
    <ul>
      <li class="node" >Root node 1
        <ul>
          <li id="child_node_1">Child node 1</li>
          <li>Child node 2</li>
        </ul>
      </li>
      <li class="node" >Root node 2</li>
    </ul>
  </div>
  <button>demo button</button>

  <!-- 4 include the jQuery library -->
  <script src="dist/libs/jquery.js"></script>
  <!-- 5 include the minified jstree source -->
  <script src="dist/jstree.min.js"></script>
  <script>
  $(function () {
    // 6 create an instance when the DOM is ready
  $("#jstree").jstree({
      "checkbox": {
          "keep_selected_style": false
      },
      "plugins": ["checkbox"]
  });

  $(".node").find('> a > .jstree-checkbox').remove()
});
  </script>

现在我可以在折叠时删除父节点的复选框,但展开时会在其旁边创建复选框。

有谁知道jstree是否提供了只检查叶节点而不是级联检查的选项? 如果是这样,请分享想法。

最佳答案

我认为最好的解决方案来自 this post如下

CSS 解决方案就可以了

#id-here .jstree-open > .jstree-anchor > .jstree-checkbox,
#id-here .jstree-closed > .jstree-anchor > .jstree-checkbox { display:none; }

关于javascript - 如何创建仅在叶节点上带有复选框的复选框树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21216844/

相关文章:

javascript - 从 jQuery 对话框中删除没有十字按钮的标题栏

javascript - 使用reactjs中的选择字段初始化默认值

javascript - 键入时防止重新呈现主菜单

javascript - 动态加载 HTML/Javascript

jquery - 嵌套ajax调用的匹配结果

javascript - 动态改变 d3.js 直方图的 bin 和高度

javascript - 分配一个唯一的 URL 以单击页面加载时的特定按钮?

javascript - 如何从 JSON 存储创建 JavaScript 日期对象?

javascript - 如何循环遍历一组 jquery 对象和 .hide() 它们中的每一个

javascript - Jade 模板中的日期选择器