模拟数据
data () {
return {
array: [
{
id: 1,
name: 云朵,
statevoid: false
},
{
id: 2,
name: 白云,
statevoid: false
},
{
id: 3,
name: 彩虹,
statevoid: false
}
],
parray: [
{
id: 2,
name: 云朵,
statevoid: false
},
{
id: 6,
name: 白云,
statevoid: false
},
{
id: 7,
name: 彩虹,
statevoid: false
}
]
}
}
js部分
var mapper = {}
this.array.forEach(function (item, index, array) {
mapper[item.id] = index
})
// console.log(mapper)
let that = this
this.parray.forEach(function (item, index, array) {
let value = mapper[item.id]
// console.log(value)
if (value !== undefined) {
that.array[value].statevoid = true
}
})
console.log(this.array)