data: {
goodReceiveNote:{ id:1,netTotal: null}
poDetailsList:[
0:{id:1,subTotal:300},
1:{id:1,subTotal:200}
]
}
如何在react中获取poDetailsList subTotal的总和并将其分配给goodReceiveNote中的netTotal。
将数组reduce与Object.values 组合使用
const total = Object.values(data.poDetailsList).reduce((a,b) => a + b.subTotal, 0)