data(){
return {
order:{
'overdueOrder': [],
'recentlyCompletedOrders': [
{'id':7,'orderName':111}
],
'workOrdersInProduction': [
{'id': 3, 'rate': 0.6},
{'id': 6, 'rate': 0.2}
]
}
}
},
watch: {
socketData: {
handler(val) {
//虚拟数据
val = {
"code": 0,
"type": 'indexOrders',
"message": 'success',
"data": {
'overdueOrder': [],
'recentlyCompletedOrders': [
{'id':7,'orderName':111},
{'id':7,'orderName':111},
{'id':7,'orderName':111},
{'id':7,'orderName':111}
],
'workOrdersInProduction': [
{'id': 3, 'rate': 0.8},
{'id': 6, 'rate': 0.5}
]
},
}
if (val.type === 'indexOrders') {
for (let orderItem in this.order) {
if (orderItem === 'workOrdersInProduction') {
this.order[orderItem].forEach(item => {
val.data[orderItem].forEach(item2 => {
if (item.id === item2.id) {
item.rate = item2.rate;
}
})
})
} else {
this.order[orderItem] = JSON.parse(JSON.stringify(val.data[orderItem]));
}
}
}
},
deep: true,
immediate: true
}
}
将一个数组对象根据id赋值给另外一个数组对象
最新推荐文章于 2023-05-17 19:07:42 发布