首页 > 其他 > 详细

iview table 多选 全选 反选

时间:2021-01-28 21:07:50      阅读:293      评论:0      收藏:0      [点我收藏+]

 

 

     
 <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; } } } }

assist.js文件夹
// 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 = {

};
 
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);

 

iview table 多选 全选 反选

原文:https://www.cnblogs.com/hao-1234-1234/p/14341481.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!