【问题标题】:JsTree Get selected node siblings and sub-siblings idsJsTree 获取选定的节点兄弟姐妹和子兄弟ID
【发布时间】:2020-09-09 10:06:06
【问题描述】:

我正在使用 jstree 将部门绘制为树,这个问题是如果我点击 a Node(root) 我只会得到第一个兄弟姐妹的 ID;但是我也想获得与同一根相关的子兄弟ID。

这是我的代码:

     var currentNode = $("#jstree").jstree("get_selected");
     var childrens = $("#jstree").jstree("get_children_dom", currentNode);
    for (var i = 0; i < childrens.length; i++) {
      alert(childrens[i].id);
    }

【问题讨论】:

  • 使用get_json函数遍历兄弟节点
  • 你能给我举个例子吗

标签: jstree


【解决方案1】:

您可以使用 jsTree get_node 函数来获取节点的 JSON 表示,其中包括所有节点兄弟的数组。

$('#jstree').bind('select_node.jstree', function (e, data) {
    var tree = $('#jstree').jstree(true);
    var siblings = tree.get_node(data.selected).children_d;
    console.log(siblings);
});

【讨论】:

    猜你喜欢
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多