父子嵌套数据,把每层的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":[]
                                }]
                                                }]
                                }]

回复

共2条回复 我来回复
  • 代码客栈
    这个人很懒,什么都没有留下~
    评论
    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);
    
    0条评论
  • 毕设工厂
    这个人很懒,什么都没有留下~
    评论
    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);
    
    0条评论

发表回复

登录后才能评论