如何为一个对象增加一个成员?

发布于 6 年前作者 xiaqiao10963 次浏览最后编辑 6 年前来自 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 回复
xiejuan
xiejuan1 楼6 年前
let rwx = [];

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

this.setData({

 rwx: rwx

})


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

jing96
jing962 楼5 年前

谢邀

this.data.rwx = []

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