当返回的数据类型如下:

  tableData: [
{
name: '张三',
occupation: '经理',
experiences: [
{ id: '123456', project: '香蕉', score: '90' },
{ id: '223456', project: '菠萝', score: '91' },
{ id: '323456', project: '西瓜', score: '95' } ],
gender: '男'
},
{
name: '李四',
occupation: '技术总监',
experiences: [
{ id: '123456', project: '香蕉', score: '92' },
{ id: '423456', project: '橘子', score: '93' } ],
gender: '男'
},
{
name: '王二',
occupation: '技术总监',
experiences: [
{ id: '123456', project: '香蕉', score: '90' },
{ id: '223456', project: '菠萝', score: '91' },
{ id: '323456', project: '西瓜', score: '95' },
{ id: '423456', project: '橘子', score: '87' } ],
gender: '男'
}
],

展示效果如下

代码如下

<template>
<div class="home">
<el-table :data="tableData" stripe style="width: 100%">
<el-table-column width="180"
v-for="(item,idx) in finalColumns" :key='idx' :label='item.label' :prop='item.prop'>
</el-table-column> </el-table>
</div>
</template> <script>
export default {
name: 'Home',
components: {},
data () {
return {
tableData: [
{
name: '张三',
occupation: '经理',
experiences: [
{ id: '123456', project: '香蕉', score: '90' },
{ id: '223456', project: '菠萝', score: '91' },
{ id: '323456', project: '西瓜', score: '95' } ],
gender: '男'
},
{
name: '李四',
occupation: '技术总监',
experiences: [
{ id: '123456', project: '香蕉', score: '92' },
{ id: '423456', project: '橘子', score: '93' } ],
gender: '男'
},
{
name: '王二',
occupation: '技术总监',
experiences: [
{ id: '123456', project: '香蕉', score: '90' },
{ id: '223456', project: '菠萝', score: '91' },
{ id: '323456', project: '西瓜', score: '95' },
{ id: '423456', project: '橘子', score: '87' } ],
gender: '男'
}
],
data: [],
columns: [
{ label: '姓名', prop: 'name' },
{ label: '应聘职务', prop: 'occupation' },
{ label: '', prop: 'experiences', children: [] },
{ label: '性别', prop: 'gender' }
],
finalColumns: []
}
},
created () {
let max = 0
let arr = []
this.tableData.forEach((ele) => {
if (max < ele.experiences.length) {
arr = []
}
ele.experiences.forEach((item, idx) => {
ele[item.id] = item.score ? item.score : '-'
if (max < ele.experiences.length) {
const obj = {}
obj.label = item.project
obj.prop = item.id
arr.push(obj)
}
})
if (max < ele.experiences.length) {
max = ele.experiences.length
}
})
console.log(this.tableData)
this.columns.forEach(ele => {
if (ele.prop === 'experiences') {
ele.children = arr
}
})
this.finalColumns = this.columns.reduce((sum, col) => {
if (col.children && col.children.length) {
sum.splice(sum.length, 0, ...col.children.map(v => v))
} else {
sum.splice(sum.length, 0, col)
}
return sum
}, [])
console.log(this.finalColumns, 'columns')
}
}
</script>

最新文章

  1. C#的Socket实现UDP协议通信
  2. js 控制浏览器窗口大小
  3. hdu 1166 敌兵布阵(树状数组)
  4. Microsoft Visual Studio 2013 VSTS单元测试指南
  5. CSS 仿Excel表格功能
  6. Android -- 自定义View(一)
  7. Shell 的source命令
  8. DBNull与Null
  9. Object-c KVC的使用和举例
  10. 十条最有效的PCB设计黄金法则
  11. redis 简易监控的几种方法
  12. Git 上传 GitHub
  13. JDK源码及其他框架源码解析随笔地址导航
  14. Python3 面向对象编程之程序设计思想发展
  15. 华莱士的 第二个python程序之(格式化输出)
  16. Oracle课程档案,第十七天
  17. jQuery实现购物车物品数量的加减
  18. Maven手动安装jar包到仓库
  19. 转载:erlang实现安卓和IOS的推送。
  20. 启动jenkins服务错误

热门文章

  1. requests模块已经安装,vs code下无法导入requests模块
  2. Exception in thread &amp;amp;quot;main&amp;amp;quot; java.lang.ArrayIndexOutOfBoundsException: 1
  3. 【Redis技术专区】「优化案例」谈谈使用Redis慢查询日志以及Redis慢查询分析指南
  4. (20)go-micro微服务Elasticsearch使用
  5. 深入Typescript--03-Typescript中的类(努力加餐饭)
  6. DLL的两种加载方式
  7. VMware vSphere vCenter ServerAppliance 7.0安装配置
  8. GitHubDesktop推送报错“SSL/TLS connection failed”如何解决
  9. sun.security.validator.ValidatorException: PKIXpath building failed: sun.security.provider,javax.net.ssT.SSLHandshakeExceptions.certpath.SunCertPathBuilderException
  10. 10月31日ATM编写逻辑描述