簡體   English   中英

如何使用ID數組在jstree中打開節點?

[英]How to open nodes in jstree using an array of ids?

我正在使用jstree javascript插件,並且正在異步加載數據。 我正在嘗試對該樹的數據執行搜索。 我有一個Web服務,該服務根據搜索參數返回一個ID數組。 搜索前未加載樹。 當用戶單擊搜索時,基於返回的ID,我試圖一一對應於ID加載/打開樹中的節點。

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

但是,僅根節點正在加載。 有人可以建議一個簡單的函數來使用ID數組逐個加載節點嗎?

提前致謝。

如果未加載jsTree,則可以在構建jsTree的數據時對要在加載時打開的節點使用“ state” =>“ open”。 請參見下面的示例-從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 */ ]
}

暫無
暫無

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

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