微信小程序-單選


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)

},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM