【问题标题】:Check if all nodes are expanded - jstree检查是否所有节点都展开 - jstree
【发布时间】:2017-10-02 10:20:27
【问题描述】:

我正在使用jstree 库,我正在尝试了解如何在展开一个节点后检查树的所有节点是否展开。我想使用此功能来设置打开/关闭天气所有节点都已扩展或所有节点未扩展。

【问题讨论】:

    标签: javascript jquery jstree


    【解决方案1】:

    如果要检查所有节点是否处于折叠状态或至少一个节点已展开,则可以使用以下检查。

    $('#btnCheck').click(function () {
        $('#status').text("No - all nodes are collapsed");
        if($('#SimpleJSTree li.jstree-open').length)
        {
            $('#status').text("Yes - there is expanded node");
        }
     });
    

    其中 jsTree id 是 SimpleJSTree 并且 jstree-open 类用于扩展节点。

    完整例子可以参考https://everyething.com/jsTree-check-for-any-expanded-node

    【讨论】:

      【解决方案2】:

      实际上有一个使用 jsTree after_open 事件的解决方案(我尝试使用 show_all 事件,但这对我不起作用):

      http://jsfiddle.net/softxide/1fnbzjjf/15/

      $('#container').on('after_open.jstree', function(e, data) {
              var closed_count = $(".jstree-closed").length;
              if(closed_count == 0)
              {
                  alert("all opened");
              }
      
                   }).jstree();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多