var json = [{tcName:"11", children:[{tcName:"22", children:[{tcName:"33"}]}, {tcName:"44", children:[{tcName:"55"}, {tcName:"55"}]}]}];
readTree(json[0], $("#load"));
function readTree(node, ul) {
var li = $(["<li>" +
"<a href=\"", "/ccs", "/trainCenter/index.do?get=\"", 12, "\">", node.tcName, "</a>" +
"</li>"].join("")).appendTo(ul);
var children = node.children;
if (children && children.length) {
ul = $("<ul></ul>").appendTo(li);
for (var i = 0; i < children.length; i++) {
readTree(children[i], ul);
}
}
}
页面
<ul id="load"></ul>
显示结果:
。11
。22
33
。44
55
55
readTree(json[0], $("#load"));
function readTree(node, ul) {
var li = $(["<li>" +
"<a href=\"", "/ccs", "/trainCenter/index.do?get=\"", 12, "\">", node.tcName, "</a>" +
"</li>"].join("")).appendTo(ul);
var children = node.children;
if (children && children.length) {
ul = $("<ul></ul>").appendTo(li);
for (var i = 0; i < children.length; i++) {
readTree(children[i], ul);
}
}
}
页面
<ul id="load"></ul>
显示结果:
。11
。22
33
。44
55
55