export function myContact(target: any, source: any) {
for (const [key, value] of Object.entries(source)) {
const [name, index] = key.split('-') // 要求key只能有一个'-'字符,前面是price之类的name,后面是index数字
if (name === 'price') { // 可以自定义判断,前缀
target[Number(index)].price = value
}
}
return target
}
//结果值
[
{
"styleName": "我们",
"styleId": 2,
"styleValue": "",
"price": "12312"
},
{
"styleName": "我们",
"styleId": 7,
"styleValue": "",
"price": "12312"
}
] 初始数据值
[
{
"styleName": "我们",
"styleId": 2,
"styleValue": "",
},
{
"styleName": "我们",
"styleId": 7,
"styleValue": "",
}
] 初始数据值
{
"price-0": "12312",
"price-1": "12312",
"price-2": "12312"
}