Iview表格点击下一页获取复选框的值以及复选框选中后的回显

 <Table
            :columns="columns"
            :data="list"
            ref="purchaseTable"
            @on-selection-change="selectTable"
            @on-select-cancel="selectCancel"
          />

添加两个事件 参考iview官方文档https://www.iviewui.com/components/table
在这里插入图片描述

 selectTable(arr) {
      arr.forEach((item) => {
        if (!this.selectEmploy.includes(item.id)) {
          this.selectEmploy.push(item.id);
        }      
      });
    },

维护一个数组 selectEmpoyee 用于存放checked选中后的表格数据 确保id的唯一性

selectCancel(selection, row) {
      this.selectEmploy = this.selectEmploy.filter((item) => {
        return item != row.id;
      });
    },

多选情况下点击取消时会触发该方法 接受两个参数 第一个为选中项 第二个为取消项
将取消项的id移除即可 方法有很多

回显

async pageChange(val) {
      let result = await saffAPI.queryEmpPositionPage({
        currPage: val,
        pageSize: 20,
        model: {
          ...this.form,
          companyType: this.companyType,
          companyId: this.companyId,
          roleId: this.id,
          excludeRole: this.type == "add",
          orgIds: this.selectdArr,
        },
      });
      //回显
      this.selectEmploy.forEach(item=>{
        result.records.forEach(element=>{
          if(element.id==item){
            this.$set(element,'_checked',true)
          }
        })
      })
      this.list = result.records;
      this.queryPage.total = result.total;
    },

触发翻页按钮时 判断请求到的数据的id值 是否在维护的selectEmpoyee数组里面 iview提供了_checked的属性 设置true即为选中

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值