合并数组对象算法
数据 A:
[
{
"id":340,
"name":"门类",
"sub":[
{
"id":341,
"name":"房门"
},
{
"id":367,
"name":"门类配件",
"children":[
{
"id":427,
"name":"门锁"
}
]
}
]
}
]
数据 B:
[
{
"id":340,
"name":"门类",
"sub":[
{
"id":342,
"name":"卫生间门"
},
{
"id":367,
"name":"门类配件",
"children":[
{
"id":428,
"name":"门吸"
}
]
}
]
},
{
"id":344,
"name":"洁具/卫浴",
"sub":[
{
"id":347,
"name":"马桶"
},
{
"id":363,
"name":"卫浴五金",
"children":[
{
"id":421,
"name":"龙头套装"
}
]
}
]
}
]
数据 B 合并到数据 A 结果:
[
{
"id":340,
"name":"门类",
"sub":[
{
"id":341,
"name":"房门"
},
{
"id":367,
"name":"门类配件",
"children":[
{
"id":427,
"name":"门锁"
},
{
"id":428,
"name":"门吸"
}
]
},
{
"id":342,
"name":"卫生间门"
}
]
},
{
"id":344,
"name":"洁具/卫浴",
"sub":[
{
"id":347,
"name":"马桶"
},
{
"id":363,
"name":"卫浴五金",
"children":[
{
"id":421,
"name":"龙头套装"
}
]
}
]
}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用 Lodash 的
mergeWith
,要写个自定义的合并函数来处理数组