簡體   English   中英

在一個節點之后添加一個節點(jstree)

[英]Adding a node just after one node (jstree)

我正在使用jstree javascript庫https://www.jstree.com/創建樹。我需要在當前節點之后創建一個新節點作為同級節點。

  • 元素1
  • 元素2
  • 元素3

我的觀點是,當我單擊Elem 2時,在Elem 2和Elem 3之間添加了一個新節點Elem 2.5。

結果是:-

  • 元素1
  • 元素2
  • 元素2.5
  • 元素3

我當前的代碼: $(".appendTree").jstree('create_node', CurrentNode, html, 'last');

通過這個新的節點總是在最后添加。是否有任何api或解決方法來處理?

您將必須找出當前文件夾中所選節點的當前索引,然后將索引傳遞給create_node方法,而不是您的last 請參見下面的代碼。 檢查演示- 小提琴演示

$('.appendTree')
        .jstree({   
        core : {
            check_callback : true,
            data : coredata
        }
    })
    .on("select_node.jstree", function (e, data) {
        var $parent = $('#'+data.node.id).parent();
                var index = $parent.children().index( $('#'+data.node.id) ) +1;

        if(data.node.parent === '#') {
            $parent = '#';
        }

        $(".appendTree").jstree('create_node', $parent, 'new node', index);
    }); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM