2013-12-17 47 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]); 
       } 
      });