微信小程序-单选

wxml
<view class='taskAll_pic'>
<view class='titleTxet'>图片</view>
<view class='picBgInput'>
<view wx:for='{{changeList}}' wx:for-item='item' class='imgFath' bindtap='changePic' data-index='{{index}}'>
<image class='changShow' src='{{item.isSeleted==false?item.icon:sleectedIcon}}'></image>
<image class='changImg' src='{{item.img}}'></image>
</view>
</view>
</view>
 
js
 
changeList: [
{ "icon": "/images/attic/round.png", "img": "/images/attic/father.png", 'isSeleted': false },
{ "icon": "/images/attic/round.png", "img": "/images/attic/good.png", 'isSeleted': false },
{ "icon": "/images/attic/round.png", "img": "/images/attic/mather.png", 'isSeleted': false },
{ "icon": "/images/attic/round.png", "img": "/images/attic/my.png", 'isSeleted': false },
{ "icon": "/images/attic/round.png", "img": "/images/attic/tv.png", 'isSeleted': false }
],
// 选择 图片
changePic(e){
if (this.data.changeList[e.currentTarget.dataset.index].isSeleted == false){
this.data.changeList[e.currentTarget.dataset.index].isSeleted = true
}

if (this.data.changeList[e.currentTarget.dataset.index].isSeleted == true){
for (let ii in this.data.changeList){
//下标不为 e.currentTarget.dataset.index 全为 false
if ( ii != e.currentTarget.dataset.index){
this.data.changeList[ii].isSeleted = false;
}
}
}

this.setData({
changeList: this.data.changeList,
icon: this.data.changeList[e.currentTarget.dataset.index].img
})

console.log(this.data.icon)

},
posted @ 2018-09-07 09:23  heart中的烦恼哟  阅读(1424)  评论(0编辑  收藏  举报