js遍历jsonTree

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

上一篇:Binary Search Tree 以及一道 LeetCode 题目


下一篇:循序渐进Python3(六) -- 初识内置变量、反射、递归