父子嵌套数据,把每层的children单独成一个list
课程设计
1
"data":[{
"code":"XSO00008",
"name":"LAZBOY经营部",
"sonList":[
{
"code":"XSO00072",
"name":"华中中心",
"sonList":[
{
"code":"XSO00185",
"name":"华中一区",
"sonList":[
{
"code":"XSO00608",
"name":"江苏一区",
"sonList":[]
},
{
"code":"XSO00480",
"name":"河南一区",
"sonList":[]
}]
}]
}]
},{
"code":"XSO00008",
"name":"LAZBOY经营部",
"sonList":[
{
"code":"XSO00072",
"name":"华中中心",
"sonList":[
{
"code":"XSO00185",
"name":"华中一区",
"sonList":[
{
"code":"XSO00608",
"name":"江苏一区",
"sonList":[]
},
{
"code":"XSO00480",
"name":"河南一区",
"sonList":[]
}]
}]
}]
-
var data=[{ "code":"XSO00008", "name":"LAZBOY经营部", "sonList":[ { "code":"XSO00072", "name":"华中中心", "sonList":[ { "code":"XSO00185", "name":"华中一区", "sonList":[ { "code":"XSO00608", "name":"江苏一区", "sonList":[] }, { "code":"XSO00480", "name":"河南一区", "sonList":[] }] }] }] },{ "code":"XSO00008", "name":"LAZBOY经营部", "sonList":[ { "code":"XSO00072", "name":"华中中心", "sonList":[ { "code":"XSO00185", "name":"华中一区", "sonList":[ { "code":"XSO00608", "name":"江苏一区", "sonList":[] }, { "code":"XSO00480", "name":"河南一区", "sonList":[] }] }] }] }] var list1=[],list2=[],list3=[],list4=[]; for(var o of data){ list1.push({code:o.code,name:o.name}); for(var p of o.sonList){ list2.push({code:p.code,name:p.name}); for(var q of p.sonList){ list3.push({code:q.code,name:q.name}); for(var r of q.sonList){ list4.push({code:r.code,name:r.name}); } } } } console.log(list1); console.log(list2); console.log(list3); console.log(list4);
-
var data=[{ "code":"XSO00008", "name":"LAZBOY经营部", "sonList":[ { "code":"XSO00072", "name":"华中中心", "sonList":[ { "code":"XSO00185", "name":"华中一区", "sonList":[ { "code":"XSO00608", "name":"江苏一区", "sonList":[] }, { "code":"XSO00480", "name":"河南一区", "sonList":[] }] }] }] },{ "code":"XSO00008", "name":"LAZBOY经营部", "sonList":[ { "code":"XSO00072", "name":"华中中心", "sonList":[ { "code":"XSO00185", "name":"华中一区", "sonList":[ { "code":"XSO00608", "name":"江苏一区", "sonList":[] }, { "code":"XSO00480", "name":"河南一区", "sonList":[] }] }] }] }] var list1=[],list2=[],list3=[],list4=[]; for(var o of data){ list1.push({code:o.code,name:o.name}); for(var p of o.sonList){ list2.push({code:p.code,name:p.name}); for(var q of p.sonList){ list3.push({code:q.code,name:q.name}); for(var r of q.sonList){ list4.push({code:r.code,name:r.name}); } } } } console.log(list1); console.log(list2); console.log(list3); console.log(list4);
发表回复