<checkbox-group bindchange=“checkboxChange”>
<view class=‘alarm-item’ wx:for="{{alarms}}">
<checkbox class=‘check’ checked="{{selectedAlarms}}.indexOf({{item.Id}})>0" value=’{{item.Id}}’></checkbox>
<view class=‘alarm-item-data’ data-id=’{{item.Id}}’ bindtap=‘getAlarmDetail’>
</view>
</view>
</checkbox-group>
有一个全选按钮 点击反选 可以把selectedAlarms 置空 但是checkbox为什么一直是选中状态?
<checkbox-group bindchange=“checkboxChange”>
<view class=‘alarm-item’ wx:for="{{alarms}}">
<checkbox class=‘check’ checked="{{selectedAlarms.indexOf(item.Id)>=0}}" value=’{{item.Id}}’></checkbox>
<view class=‘alarm-item-data’ data-id=’{{item.Id}}’ bindtap=‘getAlarmDetail’></view>
</view>
</checkbox-group>
<checkbox-group bindchange=“checkAll”>
<checkbox value=‘checkedAll’ class=‘check’>
<label>全选</label>
<view>{{selectedAlarms.length}}</view>
</checkbox>
</checkbox-group>
checkAll: function (e) {
if (e.detail.value[0]){
var newselected=[];
this.data.alarms.forEach(function (val){
newselected.push(val.Id);
});
this.setData({
selectedAlarms: newselected,
});
}else
{
this.setData({
selectedAlarms: [],
});
}
},
checkboxChange: function (e) {
this.setData({
selectedAlarms: e.detail.value,
});
},
data: {
alarms: [],
selectedAlarms: [],
},