Small micro-channel program similar to cancel thumbs thumbs counting function

This method is to write functional single article, there is a need for the kind of background to return a list of the plurality of data points like this feature can give me a message, explore

This feature is currently writing a fake data directly on the code

html

<view wx:for="{{shoucang}}" wx:key="{{index}}" data-index='{{item.id}}'>
<view wx:if="{{item.collected==1}}">
<icon catchtap='onCollectionTap1' data-index='{{index}}' style="font-size:19px" class="iconfont iconshoucang2"></icon>
<text class="text">收藏</text>
</view>
<view wx:else>
<icon catchtap='onCollectionTap1' data-index='{{index}}' style="font-size:19px;color:red;" class="iconfont iconshoucang1"></icon>
<text class="text">{{item.dzzs}}</text>
</view>
</view>
 
The data js
shoucang: [{dzzs: '22', collected: 1, id: 1}],
 
js
 
// Change the thumbs state
onCollectionTap1: function (event) {
// Get the current click subscript
var index = event.currentTarget.dataset.index;
// data acquired list
var shoucang = this.data.shoucang;
for (let i in shoucang) {// traverse the list data
if (i == index) {// find the target in accordance with the subscript
var collectStatus = false
if (shoucang [i] .collected == 0) {// if no point Like +1
collectStatus = true
shoucang[i].collected = parseInt(shoucang[i].collected) + 1
shoucang [i] .dzzs = parseInt (shoucang [i] .dzzs) + 1
} else {
collectStatus = false
shoucang[i].collected = parseInt(shoucang[i].collected) - 1
shoucang [i] .dzzs = parseInt (shoucang [i] .dzzs) - 1
}
wx.showToast({
title: collectStatus 'unsubscribe':? 'Bookmarked'
})
}
}
this.setData({
shoucang: shoucang
})
},
 

 

Guess you like

Origin www.cnblogs.com/lishuang2243/p/11069851.html