JS 树形递归实例代码
代码如下:
var l=json.length; var arr = []; for(var i = 0; i < l; i++){ (function(){ var jsonArray =arguments[0]; for(var k in jsonArray){ if(k.indexOf('children') != -1 && jsonArray[k] != null){ arguments.callee(jsonArray[k]); } else{ if(k == 'name' || k == 'children'){ arr.push(jsonArray[k]+''); } } } })(json[i]); }
JSON如下所示:
代码如下:
[{"id":"001","name":"上海市浦东新区","children":{"id":"002","name":"上海市徐汇区"}}]
相关推荐
somebodyoneday 2020-06-15
adonislu 2020-06-02
baijinswpu 2020-02-19
adonislu 2020-02-14
83163452 2020-01-28
adonislu 2020-01-10
baijinswpu 2020-01-01
adonislu 2019-12-31
baijinswpu 2019-12-28
xufankang 2019-12-19
somebodyoneday 2019-12-07
abcx 2015-05-25
somebodyoneday 2019-10-30
newthon 2019-10-21
ZCMUCZX 2016-04-14
iovaaron 2015-04-10
Dolphinsz 2016-04-25