我有一個使用json數據格式的jsTree。 加載根節點集很好。如何將json變量作爲子節點添加使用「jstree」jquery插件 - no ajax
我的問題是如何將子節點附加到被單擊的父節點。
任何幫助將不勝感激。
謝謝!
$("#tree-cat1")
.bind("open_node.jstree", function (event, data) {
console.log(data.rslt.obj.attr("id"));
//eval(loadChild());
//at this point i need to append the result of loadChild() to the tree under the relevant node
})
.jstree({
"json_data": {
"data": eval(loadRoot())
},
"themes": {"theme": "classic","dots": true,"icons": true},
"plugins": ["themes", "json_data", "ui"]
})
function loadRoot() {
return "[{'data':'A node','state':'closed','attr':{'id':'A'}}]";
}
function loadChild() {
return "[{'data':'A1 node','attr':{'id':'A1'}}]";
}
做你想做的每一個節點將被打開時添加的孩子嗎?爲什麼你不使用'兒童'屬性追加樹初始化 – Irishka
每次節點擴展時我運行oracle查詢來獲取數據(全部在JavaScript中)。數據返回到一個js變量。然後,我必須在樹中的相關點處填充返回數據的樹(根據代碼示例) – lance