2013-12-17 57 views
3

我試圖更新open_node.jstree事件上的JSTree結構。它應該填充已打開父項的子項。在樹中的特定位置創建JSTree節點

treeContent.jstree({ 
     "json_data": {"data": jsonData}, 
     "progressive_render": "true", 
     "plugins": ["themes", "json_data", "ui", "checkbox"] 
    }) 

在這一部分jsonData是加載到從一個Ajax調用收到樹中的實際數據。 我想一個綁定事件是這樣的:

.bind("open_node.jstree", function (event, data) { 
       children = data.inst._get_children(data.rslt.obj); 
       for (i = 0; i < children.length; i++) { 
        //this doesn't work 
        treeContent.jstree("create", children[i], "inside", getJSONData(children[i].getAttribute('path')));       
       } 
      }); 

通過不工作,我的意思是將正確的數據是從getJSONData收到,但子元素不會改變。

而不是行不工作我需要從getJSONData()函數設置每個孩子的數據。它以與首次加載jsonData時使用的格式相同的格式返回數據 - 一個JSON對象。

我該怎麼做?

回答

1

我已經成功地實現我想要的東西,但它似乎是一個黑客:

.bind("open_node.jstree", function (event, data) { 
       children = data.inst._get_children(data.rslt.obj); 
       for(var i=0; i<children.length; i++){ 
        data.inst.create_node(data.rslt.obj, "inside", getJSONData(children[i].getAttribute('path'))); 
        data.inst.delete_node(children[i]); 
       } 
      });