微信小程序 多选框全选与取消全选

page({

data: { select_all:false,

listData: [{code: "111",text: "text1",typ: "type1",},

{code: "021",text: "text2",typ: "type2",},

{code: "111",text: "text1",typ: "type3",}]}

selectall: function() {//全选与反全选

var that = this;

for (let i = 0; i < that.data.listData.length; i++) {

that.data.listData[i].checked = (!that.data.select_all)}

that.setData({

listData: that.data.listData,

select_all: (!that.data.select_all)

})}

})

<view class="scroll">

<scroll-view scroll-x="true">

<checkbox-group class="table" >

<view class="tr">

<view class="th">

<checkbox value="all" bindtap="selectall" />全选

</view>

<view class="th">运号</view>

<view class="th">V号</view>

<view class="th">运商</view>

<view class="th">返单</view>

<view class="th">日期</view>

</view>

<view class="tr" wx:for="{{listData}}" wx:key="">

<view class="td">

<checkbox value="{{item.code}}" checked="{{item.checked}}" />

</view>

<view class="td" value="{{item.text}}">{{item.code}}</view>

<view class="td" value="{{item.text}}">{{item.text}}</view>

<view class="td" value="{{item.typ}}">{{item.typ}}</view>

<view class="td" value="{{item.typ}}">{{item.typ}}</view>

<view class="td" value="{{item.typ}}">{{item.typ}}</view>

</view>

</checkbox-group>

</scroll-view>

</view>

</view>

.table{

background-color: #fff;

border:1px solid #dadada;

width:1200rpx;

margin-left:0rpx;

}

.tr{

background-color: #dadada;

white-space: nowrap;

width:100%;

display: flex;

text-align: center;

justify-content: center;

}

.th{

background-color: #fff999;

text-align: center;

justify-content: center;

width: 100%;

border-bottom: 1px solid #dadada;

border-right: 1px solid #dadada;

}

.td{

background-color: #fff;

text-align: center;

justify-content: center;

width: 100%;

border-bottom: 1px solid #dadada;

border-right: 1px solid #dadada;

}

效果图:

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值