博客
关于我
vue 处理表格数据:一行放多个记录
阅读量:235 次
发布时间:2019-03-01

本文共 3818 字,大约阅读时间需要 12 分钟。

后端返回的是一条一条的数据,前端需要在一行中显示三个记录,并且每列的排序号需要依次排

table代码:

序 号 学 号 姓 名 性 别 备 注 序 号 学 号 姓 名 性 别 备 注 序 号 学 号 姓 名 性 别 备 注
{ {stu.rowid}} { {stu.stid}} { {stu.name}} { {stu.sex}} { {stu.remark}} { {stu.rowid1}} { {stu.stid1}} { {stu.name1}} { {stu.sex1}} { {stu.remark1}} { {stu.rowid2}} { {stu.stid2}} { {stu.name2}} { {stu.sex2}} { {stu.remark2}}

整理数据的js代码:

res.data.rows.forEach(row => {                            row.stus = [];                            var split = parseInt(row.stulist.length / 3);                            if (row.stulist.length % 3 > 0) {                                split++;                            }                            for (var j = 0; j < split; j++) {                                var sturow = {};                                for (var i = 0; i < 3; i++) {                                    var index = i * split + j;                                    var crow = row.stulist[index];                                    if (crow) {                                        switch (i) {                                            case 0:                                                sturow.rowid = crow.rowid;                                                sturow.stid = crow.stid;                                                sturow.name = crow.name;                                                sturow.sex = crow.sex;                                                sturow.remark = crow.remark;                                                break;                                            case 1:                                                sturow.rowid1 = crow.rowid;                                                sturow.stid1 = crow.stid;                                                sturow.name1 = crow.name;                                                sturow.sex1 = crow.sex;                                                sturow.remark1 = crow.remark;                                                break;                                            case 2:                                                sturow.rowid2 = crow.rowid;                                                sturow.stid2 = crow.stid;                                                sturow.name2 = crow.name;                                                sturow.sex2 = crow.sex;                                                sturow.remark2 = crow.remark;                                                break;                                        }                                    }                                }                                row.stus.push(sturow);                            }                            that.table.data.push(row);                        });

使用嵌套循环,计算出下一个索引,取出记录,拼出一条数据,绑定到table行中

效果截图:
在这里插入图片描述

转载地址:http://garv.baihongyu.com/

你可能感兴趣的文章
MySQL 备份 Xtrabackup
查看>>
mysql 复杂查询_mysql中复杂查询
查看>>
mYSQL 外键约束
查看>>
mysql 多个表关联查询查询时间长的问题
查看>>
mySQL 多个表求多个count
查看>>
mysql 多字段删除重复数据,保留最小id数据
查看>>
MySQL 多表联合查询:UNION 和 JOIN 分析
查看>>
MySQL 大数据量快速插入方法和语句优化
查看>>
mysql 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>