Element循环表格,根据某个字段把相同的放到一起。

后端返回的数据需要把相同的字段放到一起。
代码如下:

 let arrList = res.data//获取后端返回List数据
 let cache = {};  //存储的是键是zhuanye 的值,值是zhuanye 在indeces中数组的下标
 let indices = [];  //数组中每一个值是一个数组,数组中的每一个元素是原数组中相同zhuanye的下标
 arrList.map((item, index) => {
     let departName = item.departName;//根据某个字段名
     let _index = cache[departName];
     if (_index !== undefined) {
         indices[_index].push(index)
     } else {
         cache[departName] = indices.length
         indices.push([index])
     }
 })
 let result = [];
 indices.map((item) => {
     item.map((index) => {
         result.push(arrList[index])
     })
 })
 this.tableData1 = result

版权声明:本文为weixin_48053972原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。