JS版本

  整体思路就是:不管多少层级,每层都需要添加子类进去,写个递归函数寻找子类即可

var data = [ {"txt":"成都", "key":"成都", "val":"", "parentKey":"四川", "index":1, }, {"txt":"雅安", "key":"雅安", "val":"", "parentKey":"四川", "index":1, }, {"txt":"四川", "key":"四川", "val":"", "parentKey":"", "index":0, }, {"txt":"崇州", "key":"崇州", "val":"", "parentKey":"成都", "index":1, }, ]; function addChildNode(pk){ for (var x in data){ if(data[x].parentKey==pk){ addChildNode(data[x].key); console.log("我是"+data[x].parentKey+"的:"+data[x].txt); } } } $.each(data,function(name,value) { if(value.index==0){ //console.log(value); addChildNode(value.key); } });