将json相同的值合并为数组
const product = {
"id":2,
....
"sku_list":[
{
"id":2,
"price":77.76,
"discount_price":null,
"title":"金属灰·七龙珠",
....
"specs":[
{
"key_id":1,
"key":"颜色",
"value_id":45,
"value":"金属灰"
},
{
"key_id":4,
"key":"容量",
"value_id":14,
"value":"128G"
}
],
"code":"2$1-45#3-9#4-14",
"stock":5
},
{
"id":3,
"price":77.76,
"discount_price":null,
"title":"金属银·七龙珠",
....
"specs":[
{
"key_id":1,
"key":"颜色",
"value_id":46,
"value":"银色"
},
{
"key_id":4,
"key":"容量",
"value_id":15,
"value":"256G"
}
],
"code":"2$1-45#3-9#4-14",
"stock":5
}
],
"spu_img_list":[
{
"id":165,
....
}
],
"spu_detail_img_list":[
{
"id":24,
....
}
],
"sketch_spec_id":1,
"default_sku_id":2
}
获取skuList中的specs,合并成类似如下结构:
{
name: '颜色', //key
id: '1', //key_id
list: ['金属灰', '银色'], //value
},
{
name: '容量', //key
id: '4', //key_id
list: ['128G', '256G'], //value
},