所以我有这样的数据(简化版):
const itemList = [
{itemDetail: {date: '2020-12-30' , quantity: 5, productType: 'shirt' }},
{itemDetail: {date: '2021-01-05' , quantity: 4, productType: 'trouser' }},
{itemDetail: {date: '2020-12-30', quantity: 1, productType: 'shirt' }},
{itemDetail: {date: '2021-01-05', quantity: 2, productType: 'jacket'}}
]
所需的输出:
const itemListFinalForm = [
{
date: '2020-12-30',
items: [{productType: 'shirt', quantity: 6}]
},
{
date: '2021-01-05',
items: [{productType: 'trouser', quantity: 4}, {productType: 'hat', quantity: 2}]
}
]
我已经尝试编写伪代码,但无法真正实现它。任何形式的答案将不胜感激。谢谢