如何为一个对象增加一个成员?
发布于 5 年前 作者 xiaqiao 10793 次浏览 来自 官方Issues

this.data.rwx=[]

this.data.rwx[0][‘rw’] = this.data._id//报错

或者

this.data.rwx=[]

this.data.rwx[0].rw= this.data._id//也报错

这里必须要加索引[0],因为要for循环赋值

2 回复
let rwx = [];

rwx[0] = {rw:this.data.id};

this.setData({

 rwx: rwx

})


如果需要更新视图要用setData,不能直接使用等号赋值

谢邀

this.data.rwx = []

this.data.rwx.push({rw: this.data._id})

回到顶部