如何在特定父级的jQuery Treeview中填充子节点?

时间:2011-07-13 10:13:37

标签: jquery treeview

我正在使用jQuery Treeview。是否有办法在onclick事件中填充特定父级中的子节点?请给我一些建议或简单的示例代码来做到这一点。

2 个答案:

答案 0 :(得分:0)

您可以使用

使用Javascript访问节点
document.getElementById('theParent')
    .getElementsByTagName('firstHierarchyTag')[n]
    .getElementsByTagName('secondHierarchyTag')[n]
    ...

答案 1 :(得分:0)

是的,有可能,给我们HTML代码,然后我们就能给出一个非常具体的例子。

// attach the treeview to the main ul
$("#mytree").treeview();

// listen for an event on a specific node
$("#mytreebranch").click(function() {
    var children = "<li><span class='folder'>New Children</span>"+
                   "<ul><li><span class='file'>Sub-child 1</span></li>" + 
                   "<li><span class='file'>Sub-child 2</span></li>" +
                   "</ul></li>";
     children = $(children).appendTo("#mytree");

    // add the new elements to the treeview
    $("#mytree").treeview({
        add: children
    });
});