每次当我在我的阵列上推送某些内容时,之前的结果将被替换为新的结果。 this.digital
是我从循环中推送结果的数组
mounted: function() {
for(let i = 0; i<this.order.items.length; i++){
let productId = Number(this.order.items[i].product);
for(let j = 0; j < this.products.length; j++){
if(productId === this.products[j].id){
let renderProduct = {};
renderProduct = Object.assign(this.products[j], this.order.items[i]);
if(renderProduct.delivery_type === 'Digital'){
this.digital.push(renderProduct);
}
}
}
}
},
我尝试使用map和concat,但值仍然被覆盖:
mounted: function() {
for(let i = 0; i<this.order.items.length; i++){
let productId = Number(this.order.items[i].product);
for(let j = 0; j < this.products.length; j++){
if(productId === this.products[j].id){
let renderProduct = Object.assign(this.products[j], this.order.items[i]);
if(renderProduct.delivery_type === 'Digital'){
this.digital = this.digital.concat(renderProduct);
}
}
}
}
},