2012-01-04 49 views
2
$("#orgTree").jstree({ 
    json_data: { 
     ajax:{url: ctx+"/account/org-tree.action"} 
    } 
}); 
$("#orgTree").jstree("create_node",null,"first",{attr:{id:100},data:"test"}); 

我要创建在树上一个默认的超节点,但代码:如何在jstree上创建静态节点?

$('#orgTree').jstree("create_node", null, "first", {attr : {id: 100}, data: "test"}); 

不工作,任何帮助将是巨大的。

回答

0

我有同样的问题,我解决它的方式是通过附加到树上的loaded事件,只在之后插入超级节点创建树的其余部分。另外,我并没有传入null,而是传入了树中的第一个节点。在你的情况下,它看起来像:

var $tree = $("#orgTree"); 
$tree.jstree({ 
    json_data: { 
     ajax:{url: ctx+"/account/org-tree.action"} 
    } 
}); 

$tree.on("loaded.jstree", function(event, data) { 
    var supernode = {attr : {id: 100}, data: "test"}; 

    $tree.jstree("create_node", $("li:first", $tree), "before", supernode); 
}); 

请注意,我用on因为我使用jQuery 1.7