【问题标题】:How to open nodes in jstree using an array of ids?如何使用 id 数组在 jstree 中打开节点?
【发布时间】:2012-12-10 19:28:53
【问题描述】:

我正在使用 jstree javascript 插件并且我正在异步加载数据。我正在尝试对这棵树的数据进行搜索。我有一个 Web 服务,它根据搜索参数返回一个 id 数组。搜索前未加载树。当用户点击搜索时,根据返回的 id,我正在尝试一一加载/打开树中与 id 对应的节点。

for(var i = 0; i < ids.length; i++){
     $("#tree").jstree("open_node", document.getElementById(ids[i]));
}

但是,只有根节点正在加载。任何人都可以建议一个简单的函数来使用 id 数组一个一个地加载节点吗?

提前致谢。

【问题讨论】:

    标签: javascript jstree


    【解决方案1】:

    如果 jsTree 未加载,您可以在为 jsTree 构建数据时对要在加载时打开的节点使用“状态”=>“打开”。请参阅下面的示例 - 从http://www.jstree.com/documentation/json_data复制的代码

    {
        "data" : "node_title",
        // omit `attr` if not needed; the `attr` object gets passed to the jQuery `attr` function
        "attr" : { "id" : "node_identificator", "some-other-attribute" : "attribute_value" },
        // `state` and `children` are only used for NON-leaf nodes
        "state" : "closed", // or "open", defaults to "closed"
        "children" : [ /* an array of child nodes objects */ ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-25
      相关资源
      最近更新 更多