在 微信小程序 中 获取 数组中的 值
html 代码
<text bindtap="onclick" data-index="{{index}}" ></text
js代码
这个是在data中的 数组 content: [
{
id:1,
img: '/pages/image/verify头像1.png',
text: '春暖花开',
text2: '还缺男生吗?我刚刚从加拿大回来',
agrees: '同意',
judge: false,
},
]
onclick: function (e) {
console.log(e)
let index = e.currentTarget.dataset.index ;//这个是 在html 中 设置的 index (索引)
this.setData({
[`content[${index}].judge`]:!this.data.content[index].judge,//通过索引来 定位到相对应的数据 ,记得使用 模板字符串 ,要不然没有效果
})
},