当前位置: 首页 > article >正文

el-table根据接口返回某一个字段合并行

根据名称相同合并行

<template>
    <div>


        <el-table :data="responseSearchIntegralAddData" :span-method="objectSpanMethod1" border style="width: 100%">
            <el-table-column prop="integralTypeName" label="名称" width="180" />
            <el-table-column prop="pointBehavior" label="类型" />
            <el-table-column prop="orSingleScoreder" sortable label="积分" />
        </el-table>
    </div>
</template>

<script setup>
const responseSearchIntegralAddData = ref([]);
const nameSpanArr = ref([])


  function objectSpanMethod1({ row, column, rowIndex, columnIndex }) {
    if (columnIndex === 0) { // 只对 name 列进行处理
      if (nameSpanArr.value[rowIndex] === undefined) {
        let count = 1;
        for (let i = rowIndex + 1; i < responseSearchIntegralAddData.value.length; i++) {
          if (responseSearchIntegralAddData.value[i].integralTypeName === row.integralTypeName) {
            count++;
            nameSpanArr.value[i] = -1; // 标记为已合并
          } else {
            break;
          }
        }
        nameSpanArr.value[rowIndex] = count;
      }
      if (nameSpanArr.value[rowIndex] > 0) {
        return {
          rowspan: nameSpanArr.value[rowIndex],
          colspan: 1
        };
      } else {
        return {
          rowspan: 0,
          colspan: 0
        };
      }
    }
  }

onMounted(() => {
    getData();
});
const getData = () => {
    const list = [
        {
            integralTypeName: "课程",
            responseSearchIntegralLists: [
                {
                    cycle: 1,
                    integralTypeName: "课程",
                    orSingleScoreder: 5,
                    orderBy: 2,
                    pointBehavior: "学习必修课",
                    status: false,
                    type: 1,
                    upperLimitScore: 3,
                },
                {
                    cycle: 2,
                    integralTypeName: "课程",
                    orSingleScoreder: 5,
                    orderBy: 3,
                    pointBehavior: "完成必修课",
                    status: true,
                    type: 1,
                    upperLimitScore: 3,
                },
                {
                    cycle: 3,
                    integralTypeName: "课程",
                    orSingleScoreder: 5,
                    orderBy: 4,
                    pointBehavior: "学习选修课",
                    status: true,
                    type: 1,
                    upperLimitScore: 3,
                },
            ],
        },
        {
            integralTypeName: "考试",
            responseSearchIntegralLists: [
                {
                    cycle: 3,
                    integralTypeName: "考试",
                    orSingleScoreder: 10,
                    orderBy: 9,
                    pointBehavior: "通过考试",
                    status: true,
                    type: 1,
                    upperLimitScore: 3,
                },
                {
                    cycle: 3,
                    integralTypeName: "考试",
                    orSingleScoreder: 10,
                    orderBy: 20,
                    pointBehavior: "上传考试",
                    status: true,
                    type: 1,
                    upperLimitScore: 5,
                },
            ],
        },
    ];
    responseSearchIntegralAddData.value = list.flatMap((item) =>
        item.responseSearchIntegralLists.map((rule) => ({
            integralTypeName: item.integralTypeName,
            ...rule,
        }))
    );
    console.log(
        responseSearchIntegralAddData.value,
        "responseSearchIntegralAddData.value"
    );
};

</script>

在这里插入图片描述


http://www.kler.cn/a/419434.html

相关文章:

  • Android矩阵Matrix实现Glide图像fitCenter转换为centerCrop,Kotlin
  • Uniapp 使用自定义字体
  • Qt 窗口类型、窗口标志和窗口属性
  • Java全栈:超市购物系统实现
  • Android习题第7章广播
  • 零基础Python学习
  • lvs虚拟服务器之LVS-NAT模式
  • unity创建一传感器,当物体经过时,计数加一
  • 大数据机器学习算法与计算机视觉应用06:梯度下降
  • mongodb文档字符串批量替换
  • 多种平台上安装部署调试Open5GS(四)
  • 高级java每日一道面试题-2024年11月28日-JVM篇-调优命令有哪些?
  • java解析json
  • 【Story】《嵌入式开发中的Bug故事:挑战、解决与成长》
  • MySQL数据库做题笔记
  • vue实现excel导出导入
  • 《黑神话:悟空》启动游戏就提示缺少C++库如何解决?
  • JS实现数据循环顺位获取元素,数组元素不足时,能够从头开始顺位取元素以补足
  • docker中redis查看key、删除key
  • git 清除旧历史提交记录并关联远程仓库
  • Qt 面试题学习11_2024-11-29
  • 力扣--LCR 143. 子结构判断
  • 挑战用React封装100个组件【006】
  • 【Springboot】@Autowired和@Resource的区别
  • TouchGFX设计模式代码实例说明
  • 基于centos7.9容器编排Jumpserver堡垒机