小程序for循环中通过index实现单个点击事件

<!--xml-->
<view class='content3-list' wx:for="{{listItems}}" >
<view class='list-left'>
<image id="{{index}}" bindtap='clickRight' src= '{{item.rightImage}}' />
<text class='list-left-wd'>{{item.word}}</text>
<text class='list-left-exp'>{{item.explain}}</text>
</view>
<view class='list-right'>
<image src="../../images/del.png" />
</view>
</view>
 
<!--js-->
Page({
// 页面的初始数据
data: {
listItems: [
{
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}
]
},
clickRight: function (e) {
var idx = parseInt(e.currentTarget.id);
var img = this.data.listItems;
if ("/images/right.png" == img[idx].rightImage) {
img[idx].rightImage = "/images/right1.png";
} else {
img[idx].rightImage = "/images/right.png";
}
}
})


posted @ 2017-12-26 14:46  joyer_lee  阅读(8413)  评论(0编辑  收藏  举报