Home > Web Front-end > JS Tutorial > JS tree recursive example code_javascript skills

JS tree recursive example code_javascript skills

WBOY
Release: 2016-05-16 18:26:52
Original
1101 people have browsed it
Copy code The code is as follows:

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 looks like this:
Copy code The code is as follows:

[{"id":"001","name":"Pudong New District, Shanghai","children":{"id":"002","name ":"Xuhui District, Shanghai"}}]
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template