把相同batch合并,并生成对应的positionList 数组
原始数组:
const list = [
{
positionId: '1001',
positionName: 'B-b-b-101',
batch: '1',
num: 5,
},
{
positionId: '1002',
positionName: 'B-b-b-102',
batch: '2',
num: 3,
},
{
positionId: '1004',
positionName: 'B-b-b-104',
batch: '1',
num: 1,
},
{
positionId: '1004',
positionName: 'B-b-b-105',
batch: '2',
num: 3,
},
]
期望数组:
const list = [
{
positionId: '1001',
positionName: 'B-b-b-101',
batch: '1',
num: 5,
positionList: [
{
positionId: '1001',
positionName: 'B-b-b-101',
num: 5,
},
{
positionId: '1004',
positionName: 'B-b-b-104',
num: 1,
},
],
},
{
positionId: '1002',
positionName: 'B-b-b-102',
batch: '2',
num: 3,
positionList: [
{
positionId: '1002',
positionName: 'B-b-b-102',
num: 2,
},
],
},
{
positionId: '1005',
positionName: 'B-b-b-105',
batch: '2',
num: 3,
positionList: [
{
positionId: '1005',
positionName: 'B-b-b-105',
num: 3,
},
],
},
]