如下有val
数组,如何处理,能够将model
和 defect
相同的内容json 合并,并且将checkpoint 字段处理成内容合并,用" | "分格,将level_score,num_score,repeat_score,cycle_score字段处理成新的数组字段,total_score字段做和
val = [
{
production_date: '2023-04-18',
checkpoint: 'ZP',
model: 'one',
defect: '坑',
dept: 'AAA',
level_score: '',
num_score: '',
repeat_score: 'ZP复发',
cycle_score: '',
total_score: 25
},
{
production_date: '2023-04-18',
checkpoint: 'ZQ',
model: 'two',
defect: '包',
dept: 'AAA',
level_score: '',
num_score: '',
repeat_score: 'ZQ复发',
cycle_score: '',
total_score: 25
},
{
production_date: '2023-04-18',
checkpoint: 'ZW',
model: 'one',
defect: '坑',
dept: 'AAA',
level_score: 'ZW等级',
num_score: '',
repeat_score: 'ZW复发',
cycle_score: '',
total_score: 45
},
]
生成结果:
new_val = [
{
production_date: '2023-04-18',
checkpoint: 'ZP | ZW',
model: 'one',
defect: '坑',
dept: 'AAA',
tags:[ 'ZW等级', 'ZP复发', 'ZW复发'],
total_score: 70
},
{
production_date: '2023-04-18',
checkpoint: 'ZQ',
model: 'two',
defect: '包',
dept: 'AAA',
tags:['ZQ复发'],
total_score: 25
},
]