//点击人员列表绑定按钮
showModal() {
this.visible = true
console.log({...this.detail})
for (const key in Object.keys(this.detail)) {
console.log({...this.detail}.key)
if (this.form.hasOwnProperty(key)) {
this.form[key] = {...this.detail}.key
}
}
console.log(this.form.hasOwnProperty('ajrybh'))
console.log(this.form.hasOwnProperty('ajmc'))
},
打印结果,就邪门,始终是undefined
然后我试着打印了一下key,才发现是0,1,2,3,,,,事情明了了,Object.keys(this.detail)就是数组得嘛,
我还去憨憨的
for去遍历,得到的就是索引,那就好办了,用foreach就好了
Object.keys(this.detail).forEach(key=> {
console.log(key)
if (this.form.hasOwnProperty(key)) {
this.form[key] = {...this.detail}.key
}
})
最后还有一个问题,虽然key没有问题了,但是最后还是无法将detail赋值到form,然后我又换了一种方式,可行
Object.keys(this.detail).forEach(key=> {
if (this.form.hasOwnProperty(key)) {
this.form[key] = this.detail[key]
}
})```
用object[key]代替object.key,具体原因待我去回顾一下文档