iview table 多选 、全选 、反选+选中行可编辑

 

 

复制代码
     
 <Table max-height="400"  ref="tbUsers"   :data='usersData' :columns="usersColumns" @on-select='tableSelect' @on-select-cancel='tableSelectCancel' @on-select-all='tableSelectAll'  @on-select-all-cancel='tableSelectAllCancel'></Table>
   
import { deepCopy } from '@/libs/assist';
 

usersData: [], usersDataTemp:[],//中间变量很关键 usersColumns: [ { type:
'selection', //maxWidth: 50, width:50, align: 'center' }, { key: 'ContractorName', width:130, title: '承包户名称', //minWidth: 80 }, { type: 'WinPrice', title: '中标价格(元)', width:160, //minWidth: 90, render: (h, {row, index}) => { let edit; if (this.usersDataTemp[index].ShowEdit ==true) { edit = [h('InputNumber', { props: { value: row.WinPrice, }, style:{ width:'140px' }, on: { input: (val) => { this.usersDataTemp[index].WinPrice = val; } } })]; }else{ edit=row.WinPrice; } return h('div', [edit]); } }, { type: 'Comment', title: '备注', //width:285, //maxWidth: 285, render: (h, {row, index}) => { let edit; if (this.usersDataTemp[index].ShowEdit==true) { edit = [h('Input', { props: { value: row.Comment, maxlength:200, }, on: { input: (val) => { this.usersDataTemp[index].Comment = val; } } })]; }else{ edit=row.Comment; } return h('div', [edit]); } }, ], methods: { getUserData(){ 异步请求获取数据data this.usersData=data; this.usersDataTemp= deepCopy(data); }, tableSelectAll(selection){ //console.log('tableSelect',selection); for(let j=0;j<this.usersDataTemp.length;j++){ this.usersDataTemp[j].ShowEdit=true; } }, tableSelectAllCancel(selection){ //console.log('tableSelectCancel',selection); for(let j=0;j<this.usersDataTemp.length;j++){ this.usersDataTemp[j].ShowEdit=false; } }, tableSelectCancel(selection,row){//已选项数据,取消选择的一项数据 //console.log('tableSelectCancel',selection,row); for(let j=0;j<this.usersDataTemp.length;j++){ if(this.usersDataTemp[j].UserID==row.UserID){ this.usersDataTemp[j].ShowEdit=false; } } }, tableSelect(selection,row){ //console.log('tableSelect',selection,row);//已选项数据,刚选择的一项数据 for(let j=0;j<this.usersDataTemp.length;j++){ if(this.usersDataTemp[j].UserID==row.UserID){ this.usersDataTemp[j].ShowEdit=true; } } } }

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
assist.js文件夹<br>// deepCopy
function deepCopy (data) {
  const t = typeOf(data);
  let o;
 
  if (t === 'array') {
    o = [];
  } else if (t === 'object') {
    o = {};
  } else {
    return data;
  }
 
  if (t === 'array') {
    for (let i = 0; i < data.length; i++) {
      o.push(deepCopy(data[i]));
    }
  } else if (t === 'object') {
    for (let i in data) {
      o[i] = deepCopy(data[i]);
    }
  }
  return o;
}
 
export {deepCopy};

也可以

 
let util = {

};
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
util.deepCopy=function (data) {
  const t = typeOf(data);
  let o;
 
  if (t === 'array') {
    o = [];
  } else if (t === 'object') {
    o = {};
  } else {
    return data;
  }
 
  if (t === 'array') {
    for (let i = 0; i < data.length; i++) {
      o.push(deepCopy(data[i]));
    }
  } else if (t === 'object') {
    for (let i in data) {
      o[i] = util.deepCopy(data[i]); //util递归没测试过
    }
  }
  return o;
}
export default util;
 
引用:
import util from '@/libs/util';
调用
util.deepCopy(data);

 

posted @   hao_1234_1234  阅读(2129)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2018-01-28 sqlserver设计器实现约束
2018-01-28 启用sa账号
2017-01-28 转载ORM--EF框架
2017-01-28 转载 HashSet用法 合交并差
点击右上角即可分享
微信分享提示