嗨,玉麟 2019-11-01 13:58 采纳率: 0%
浏览 396

数据的处理,用原生js实现两个数组的一个合并

let news = [{
    "title": "根目录",
    "id": 0,
    "children": [{
            "title": "test-yl",
            "id": 1,
            "children": [{
                    "title": "通abtest指标统计",
                    "id": 5,
                    "children": [],
                },
                {
                    "title": "test-yl2",
                    "id": 6,
                    "children": [{
                        "title": "[搜狗APP]无线黑名单数据",
                        "id": 7,
                        "children": [],
                    }],
                }
            ],
        },
        {
            "title": "是农村进口设备v",
            "id": 2,
            "children": [{
                "title": "你还欧水防护等级啊大家撒 ",
                "id": 975,
                "children": [],
            }],
        },
        {
            "title": "你的看到出发点卡萨",
            "id": 888,
            "children": [{
                "title": "是名乘客辽宁省 ",
                "id": 666,
                "children": [],
            }],
        }
    ],
}]
let old = [{
    "title": "根目录",
    "id": 0,
    "children": [{
            "title": "test-yl",
            "id": 1,
            "children": [{
                "title": "test-yl2",
                "id": 6,
                "children": [{
                    "title": "答复您尽快吧百年大计哦",
                    "id": 999,
                    "children": [],
                }],
            }],
        },
        {
            "title": "是农村进口设备v",
            "id": 2,
            "children": [{
                "title": "VB吃烧烤不过 ",
                "id": 898,
                "children": [{
                    "title": "程度不会卡两个",
                    "id": 456,
                    "children": [{
                        "title": "第三课发货大吉 ",
                        "id": 987,
                        "children": [],
                    }],
                }, ],
            }],
        },
        {
            "title": "你的看到出发点卡萨",
            "id": 888,
            "children": [{
                "title": "是名乘客辽宁省 ",
                "id": 666,
                "children": [],
            }],
        }
    ],
}]
// 合并数组,找到对应的父节点加进去,id是唯一的
// 合并结果
// [{
//     "title": "根目录",
//     "id": 0,
//     "children": [{
//             "title": "testyl",
//             "id": 1,
//             "children": [{
//                     "title": "通abtest指标统计",
//                     "id": 5,
//                     "children": [],
//                 },
//                 {
//                     "title": "test-yl2",
//                     "id": 6,
//                     "children": [{
//                             "title": "答复您尽快吧百年大计哦",
//                             "id": 999,
//                             "children": [],
//                         },
//                         {
//                             "title": "[搜狗APP]无线黑名单数据",
//                             "id": 7,
//                             "children": [],
//                         }
//                     ],
//                 }
//             ],
//         },
//         {
//             "title": "是农村进口设备v",
//             "id": 2,
//             "children": [{
//                 "title": "你还欧水防护等级啊大家撒 ",
//                 "id": 975,
//                 "children": [],
//             }, {
//                 "title": "VB吃烧烤不过 ",
//                 "id": 898,
//                 "children": [{
//                     "title": "程度不会卡两个",
//                     "id": 456,
//                     "children": [{
//                         "title": "第三课发货大吉 ",
//                         "id": 987,
//                         "children": [],
//                     }],
//                 }, ],
//             }],
//         },
//         {
//             "title": "你的看到出发点卡萨",
//             "id": 888,
//             "children": [{
//                 "title": "是名乘客辽宁省 ",
//                 "id": 666,
//                 "children": [],
//             }],
//         }
//     ],
// }]

用js怎么实现~~~

  • 写回答

2条回答 默认 最新

  • zqbnqsdsmd 2019-11-02 11:19
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料