小程序多个商品收藏

html

<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
});
},
原文地址:https://www.cnblogs.com/yaoyao-/p/11448482.html