后端返回的数据需要把相同的字段放到一起。
代码如下:
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