從后台得到的數據:
titleMap中的數據為表頭數據
key是0的對應 dataList 中的C0的值
顯示要求
let listArr = [{}] let dataList = res.data.dataList let titleMap = res.data.titleMap let length = 0; for(let ever in titleMap) { length++; } for (let i = 0; i < length; i++){ let label = "C"+i if(titleMap.hasOwnProperty(i)){ listArr[0][label]= titleMap[i] } } let dataArr = listArr.concat(dataList)
dataArr 數據如下:
el-table中循環如下:
<el-table id="productTable" :data="dataArr" border style="width: 99%" :header-cell-style="tableHeaderColor" :cell-style="cellStyle" show-summary> <el-table-column prop="orgName" align="center" label="站點名稱"></el-table-column> <el-table-column prop="treatmentSum" align="center" label="治療台次" sortable></el-table-column> <el-table-column :label="item" align="center" v-for="(item, index) in dataArr[0]" :key="index"> <template slot-scope="scope"> <span>{{scope.row[index]}}</span> </template> </el-table-column> </el-table>
tableHeaderColor({ row, column, rowIndex, columnIndex }) { if (rowIndex === 0) { return "color: #4f81bd;font-weight: bold ;"; } }, cellStyle({ row, column, rowIndex, columnIndex }) { if (rowIndex === 0) { return "display: none;"; }else { } },
OK啦!!!!!!