在 微信小程序 中? 獲取? 數(shù)組中的 值
html 代碼
<text?bindtap="onclick" data-index="{{index}}" ></text
js代碼
這個是在data中的 數(shù)組?? 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 中 設(shè)置的 index (索引)
????this.setData({
??????[`content[${index}].judge`]:!this.data.content[index].judge,//通過索引來 定位到相對應(yīng)的數(shù)據(jù) ,記得使用 模板字符串 ,要不然沒有效果
????})
??},