当返回的数据类型如下:

  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>

el-table 处理表格数据中存在属性值为数组的情况的更多相关文章

  1. ajax取到数据后如何拿到data.data中的属性值

    今天遇到的ajax取到数据后如何拿到data.data中的属性值的问题 比如拿到了数据 我要取出data中的name 题外话:当然取名最好别取什么奇怪的xiaobi

  2. jsp页面使用el 按key获取map中的对应值

    jsp页面使用el 按key获取map中的对应值 转自:<jsp页面使用el 按key获取map中的对应值>地址:http://blog.csdn.net/baple/article/de ...

  3. <s:property="a" value=""/>取的<s:debug></s:debug>中的value stack中的属性值

    <s:property="a"  value=""/>取的<s:debug></s:debug>中的value stack中 ...

  4. 将source类中的属性值赋给target类中对应的属性

    /** * 对象的属性值拷贝 * <p> * 将source对象中的属性值赋值到target对象中的属性,属性名一样,类型一样 * <p> * example: * <p ...

  5. Spring中使用@Value读取porperties文件中的属性值方法总结及注意事项

    本文为博主原创,转载请注明出处. 此前曾总结过使用工具类读取properties文件中的属性值,有兴趣的可以看一下. 如何快速获取properties中的配置属性值:https://www.cnblo ...

  6. 【Python】获取翻页之后的各页面中的属性值。

    如何获取翻页之后的页面中的html标签中的属性值? # coding=utf-8 from selenium import webdriver if __name__=="__main__& ...

  7. Implement Property Value Validation in the Application Model 在应用程序模型中实现属性值验证

    In this lesson, you will learn how to check whether or not a property value satisfies a particular r ...

  8. params.row[params.column.key] vue h函数 当前单元格 h函数 div 属性 值或数组 render

    params.row[params.column.key] vue h函数 当前单元格 h函数 div 属性 值或数组 render

  9. table(表格)中的标签和属性

    1.表格由 <table> 标签来定义.行( <tr> ),单元格(<td> ) 字母 td 指表格数据(table data),即数据单元格的内容.数据单元格可以 ...

  10. iview table 实现在数据中自定义标识

    做了一个商旅订票的项目,在详情中有一个因公超标在表格中用一个“超”字显示的需求.后台框架用的iview+vue,也就是在iview Table中改变.在iview的框架中改变东西首先要想到的是ivie ...

随机推荐

  1. 实操记录之-----Ant Design of Vue 增强版动态合并单元格,自动根据数据进行合并,可自定义横纵向合并

    前几天搞了个简易版的动态合并单元格 但是需求有变化,就只能稍微改改了~~ 欢迎路过的各位大佬指出我代码的问题~~~~ 另: 代码执行效率不是很高,如果需要大量渲染更多数据建议可以直接使用原生 < ...

  2. 详解 Gulp4 和 Gulp3 的区别

    最近在开发几个网站,为了优化一下前端代码,就复习一下gulpjs,之前工作gulp用的版本比较老,但是今天看了新的版本,新的语法出了一下,但是为了时间,我决定使用之前gulp3的旧版本,后面发现自己环 ...

  3. win32com操作word API精讲 第十集 Paragraphs & Paragraph接口 (一)

    本课程<win32com操作word API精讲&项目实战>以视频为主,文字为辅,公众号ID:一灯编程 在word编程中,Range和Paragraph(s)接口无愧于劳模接口的称 ...

  4. Unity之正确设置手机显示布局&&获取手机朝向

    目录 Unity之正确设置手机显示布局 && 获取手机朝向 前言 开篇 Unity版本及使用插件 正题 设置手机屏幕显示布局.Screen.orientation 获取手机当前朝向.I ...

  5. 我为什么要放弃RESTful,选择拥抱GraphQL

    背景 REST作为一种现代网络应用非常流行的软件架构风格,自从Roy Fielding博士在2000年他的博士论文中提出来到现在已经有了20年的历史.它的简单易用性,可扩展性,伸缩性受到广大Web开发 ...

  6. python装饰器拦截方法执行

    import time def log(delay=0): def decorator(func): def wrapper(*args, **kwargs): """我 ...

  7. 843. n-皇后问题

    题目: 这 道 题 呢 唯 一 一 点 与 其 他 题 目 不 同 之 处 就 是 它 有 有 3 个 v i s 数 组 以及是一行一行深搜的. 主要思路为: 从第一行 到第n行,一行放一个,这一行 ...

  8. Linux 常用命令(测试于CentOS8版本)

    一.文件及文件夹操作 mkdir test #创建文件夹 默认在Home/test touch test.js #创建文件 默认Home/test.js touch test/test.js #创建文 ...

  9. SQL性能优化的47个小技巧,你了解多少?

    大家好,我是哪吒. 1.先了解MySQL的执行过程 了解了MySQL的执行过程,我们才知道如何进行sql优化. 客户端发送一条查询语句到服务器: 服务器先查询缓存,如果命中缓存,则立即返回存储在缓存中 ...

  10. vue3和vue2的区别

    一.Vue3介绍 Vue 新版本的理念成型于 2018 年末,当时 Vue 2 的代码库已经有两岁半了.比起通用软件的生命周期来这好像也没那么久,但在这段时期,前端世界已经今昔非比了 在更新(和重写) ...