当我点击 checkbox 会调用 bindchange=“checkboxChange” 方法,怎么获取我每次点击的checkbox 的下标 shopIndex
因为<checkbox-group>是在循环外面且有多个checkbox 。求告知怎么获取当前点击checkbox 的下标
<checkbox-group bindchange=“checkboxChange” >
<view class=“row” wx:for="{{cart.cartslist}}" wx:for-item=“shop”
wx:for-index=“shopIndex” wx:key=“shopIndex” >
<view class=" checkbox" >
<checkbox value=’{{shop.id}}’ checked=’{{shop.checked}}’ ></checkbox>
</view>
</view>
</checkbox-group>
checkboxChange: function(e) {
console.log(e)
let cartslist = that.data.cart.cartslist;
let checkedGoodsList = e.detail.value;
for (let i = 0; i < cartslist.length; i++) {
let shop = cartslist[i];
if (shop.status == 1) {
let good_id = shop.id.toString();
let index = checkedGoodsList.indexOf(good_id);
if (index < 0) {
shop.checked = false;
} else {
shop.checked = true;
}
}
}
that.data.cart.cartslist = cartslist
that.setData({
cart: cart,
checkedGoodsList: checkedGoodsList
})
that.countOrderTotal();
},
我是这么做的,虽然麻烦了点。但是目前还能满足需求。