– 问题 --我现在点击一个商品的加减,其他商品的加减一起加一起减,我如何点击单个商品是,其他商品加减不懂,只有对应的商品的加减动。-- html –
<view class=“container”>
<view wx:for="{{userIndexProList}}" wx:key=“this” wx:for-item=“item”>
<view style=‘margin-top:35rpx;’ class=‘item_container’ bindtap=‘itemSelected’ data-index=’{{index}}’>
<image class=‘select_icon’ src="{{item.isSelected?’/images/wmn_select_have.png’:’/images/wmn_select_none.png’}}" style=‘width:40rpx;margin-right:30rpx;’></image>
</view>
<view class=“carts-text” style=‘width:calc(100% - 35rpx);’>
<text class=“carts-title”>{{item.product.title}}</text>
<text class=“carts-title”>{{item.product.items}}</text>
<view class=“carts-subtitle”>
<text class=“carts-price”>¥{{item.product.price}}</text>
<text bindtap=“bindMinus” data-index="{{index}}">-</text>
<text>{{num}}</text>
<text bindtap=“bindPlus” data-index="{{index}}">+</text>
</view>
</view>
</view>
</view>
– js –
data: {
//默认是1
num: 1,
},
//数量加
bindPlus: function() {
var num = this.data.num;
num++;
this.setData({
num: num
});
},
//数量减
bindMinus: function() {
var num = this.data.num;
if (num > 1) {
num–;
}
this.setData({
num: num
});
}