weixin_39596739
weixin_39596739
2020-12-05 12:56

Toggle node

I want an option to toggle collapse node by click (or double click) on the node title. Is this possible? Thank you.

该提问来源于开源项目:mbraak/jqTree

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39945523 weixin_39945523 5月前

    You can use the tree.click event to do this:

    
    var $tree = $('#tree1');
    $tree.tree({
        selectable: true
    });
    
    $tree.bind('tree.click', function(e) {
        var node = e.node;
    
        if (node.hasChildren()) {
            $tree.tree('openNode', node);
        }
    });
    

    Note that this does not work for double click.

    点赞 评论 复制链接分享
  • weixin_39596739 weixin_39596739 5月前

    I have already tried this option, it doesn't close the node. I didn't find functions like "isOpened" in documentation.

    点赞 评论 复制链接分享
  • weixin_39945523 weixin_39945523 5月前

    Oops, wrong example. You can use the toggle function:

    
    $tree.tree();
    $tree.bind('tree.click', function(e) {
        var node = e.node;
    
        if (node.hasChildren()) {
            $tree.tree('toggle', node);
        }
    });
    

    The toggle function is not documented yet.

    Notes:

    Node has the is_open property.

    
    $tree.bind('tree.click', function(e) {
        console.log(e.node.is_open);
    });
    

    There is a also a closeNode function.

    
    $tree.tree('closeNode', node);
    
    点赞 评论 复制链接分享
  • weixin_39596739 weixin_39596739 5月前

    Thanks a lot!

    点赞 评论 复制链接分享

相关推荐