elementUI type=“selection“多选框选中 删除 回显 赋值问题 回显数组改变选中状态未改变

业务需求:

点击查询弹列表框

勾选列表选项保存

可删除可重新查询列表添加

遇到的问题:删除之后查询列表selection回显问题

解决:@row-click配合:reserve-selection="true"使用

复制代码
      <el-table
        ref="refPlanTable"
        :data="refPlanTableData"
        tooltip-effect="dark"
        :max-height="400"
        :height="400"
        :header-cell-style="{textAlign: 'center'}"
        :cell-style="{textAlign:'center'}"
        @selection-change="handleSelectionChangeRef"
        @row-click="handleRowClickRef"
        :row-key="getRowKey"
      >
        <el-table-column type="selection" width="55" fixed="left" :reserve-selection="true"></el-table-column>
        </el-table>

handleRowClickRef(row){ this.$refs.refPlanTable.toggleRowSelection(row); },

表格data赋值的地方添加

注意::reserve-selection="true"会记录保存上一次选中的状态,所以每次赋值前要先清空选中状态

复制代码
          this.refPlanTableData=res.result;
          let string = this.multipleSelectionRef.map(item => item.identity);
          console.log(string);
          this.$nextTick(() => {
            this.refPlanTableData.forEach(item=>{
              this.$refs.refPlanTable&&this.$refs.refPlanTable.toggleRowSelection(item,false);
              if(string.includes(item.identity)){
                this.$refs.refPlanTable&&this.$refs.refPlanTable.toggleRowSelection(item,true);
              }
            })
          })
相关推荐
_lucas1 小时前
给知识库网站接入AI问答
前端·ai编程·全栈
前端糕手1 小时前
前端面试题大全:JavaScript + Vue3 + React + TypeScript + 工程化 + 性能优化
前端
我不叫武2 小时前
一个用 Rust 写的离线编码查询桌面工具
前端
Web4Browser3 小时前
指纹浏览器 API 自动化怎么接:启动 Profile、获取 CDP 端点并连接自动化框架
前端·网络·typescript·自动化
Patrick_Wilson4 小时前
从 React 到 Flutter:写给前端的一张跨端知识地图
前端·flutter·react.js
颜酱4 小时前
06 | 把 meta_config 同步进 MySQL(生成阶段)
前端·人工智能·后端
OpenTiny社区4 小时前
Loop Engineering:让 AI Agent 自己跑起来的工程方法
前端·github
IT_陈寒5 小时前
SpringBoot自动配置坑了我一周,原来问题这么蠢!
前端·人工智能·后端
kyriewen5 小时前
我review了一份Vibe Coding写的前端代码——能跑,但5个地方迟早要命
前端·javascript·ai编程
REDcker5 小时前
Cesium三维WebGIS入门详解
前端·gis·web·cesium·webgis