function handleTableData(col,row){
let a = [] //暂时存储表格表头(列)
col.forEach(e => {
a.push({
label: e.measureName+"("+e.measureUnit+")",//表头名称
id: e.valueField, //标识
fixedNum: e.decimalPlaces, //小数点后几位
})
});
let b = {}
a.forEach(e=>{
b[e.label] = []
})
a.forEach(e=>{
row.forEach(ele=>{
if(ele[e.id]){
let obj = {
meaTime: ele.meaTime,
collectionType: ele.collectionType,
remark: ele.remark,
}
obj[e.label] = Number(ele[e.id]).toFixed(e.fixedNum)
b[e.label].push(obj)
}
})
})
let c = Object.keys(b) //获取对象名
let d = Object.values(b)//获取数组列表
//获取其中长度最长的数组
let longest = d.reduce((max, current) => {
return max.length > current.length ? max : current;
});
let e = [] //以长度最长的数组为蓝本打散,组成table数组
c.forEach(ele=>{
longest.forEach((val,i)=>{
val[ele] = b[ele][i][ele]
e.push(val)
})
})
//数组去重
const f = e.filter((item, index) => e.indexOf(item) === index);
return f
};
改为
function abc(col,row){
let nameList = col.map(e=>{
return {
label: e.measureName+"("+e.measureUnit+")",//表头名称
id: e.valueField, //标识
fixedNum: e.decimalPlaces, //小数点后几位
}
})
let a= []
row.forEach(e=>{
let obj = {
meaTime: e.meaTime,
collectionType: e.collectionType,
remark: e.remark,
}
nameList.forEach(ele=>{
obj[ele.label] = e[ele.id].toFixed(Number(ele.fixedNum))
})
a.push(obj)
})
return a
};