我需要树形结构的帮助,这里我有代码,我从网上得到,我需要用扩展和折叠功能显示它...
var treeNodes = [
{parent:-1,id:0,name:'root'},
{parent:1,id:3,name:'net'},
{parent:1,id:4,name:'flash '},
{parent:3,id:7,name:'South korea'},
{parent:6,id:8,name:'West korea'},
{parent:0,id:1,name:'Microsoft'},
{parent:1,id:5,name:'Google'},
{parent:0,id:2,name:'JPmorgon Intl'},
{parent:2,id:6,name:'SW'}
];
$("#container").append( buildNestedList(treeNodes, 0) );
function buildNestedList(treeNodes, rootId) {
var nodesByParent = {};
$.each(treeNodes, function(i, node) {
if (!(node.parent in nodesByParent)) nodesByParent[node.parent] = [];
nodesByParent[node.parent].push(node);
});
function buildTree(children) {
var $container = $("<ul>");
if (!children) return;
$.each(children, function(i, child) {
$("<li>", {text: child.name})
.appendTo($container)
.append( buildTree(nodesByParent[child.id]) );
});
return $container;
}
return buildTree(nodesByParent[rootId]);
}
任何人都请指导我。我需要设置+和_图像来扩展和折叠树结构。
提前致谢