小程序多個商品收藏

htmlhtml

<image src="../../images/weishoucang.png" wx:if="{{ item.isShow }}" bindtap="clickselect" data-index="{{ index }}"></image>
<image src="../../images/shoucang.png" wx:else bindtap="clickselect" data-index="{{ index }}"></image>
 
js
clickselect: function (e) {
var index = 0;
var shopList = this.data.shop
for (let item of shopList) {
//若是當前點擊的對象id和循環對象裏的id一致
if (item.id == (e.currentTarget.dataset.index + 1)) {
if (shopList[index].isShow == "" || shopList[index].isShow == undefined) {
shopList[index].isShow = !shopList[index].isShow
} else {
shopList[index].isShow = ""
}
}
index++;
}
this.setData({
shop: shopList
});
},
相關文章
相關標籤/搜索