两个数组对象两两对比,删除一样的对象vue
tempSales = [{key:'1',value:'拼团'},{key:'2',value:'秒杀'},{key:'3',value:'满减'},{key:'4',value:'满送'}],ruleRecordCount = [{promotionType:'1',promotionCount:235},{promotionType:'2',promotionCount:21},{promo
·
tempSales = [{
key:'1',
value:'拼团'
},{
key:'2',
value:'秒杀'
},{
key:'3',
value:'满减'
},{
key:'4',
value:'满送'
}],
ruleRecordCount = [{
promotionType:'1',
promotionCount:235
},{
promotionType:'2',
promotionCount:21
},{
promotionType:'3',
promotionCount:784
},{
promotionType:'4',
promotionCount:1645
},]
for(let item1 of tempSales) {
let _index=ruleRecordCount.findIndex(c=>c.promotionType==item1.key)
if(_index>-1){
item1.count = ruleRecordCount[_index].promotionCount;
}
}
this.saleTypes=tempSales //这是最终需要挂载到页面上的值
最后的方式就是你对比出来的数组,只需要赋值就可以了,是不是感觉so esay
更多推荐
已为社区贡献1条内容
所有评论(0)