angularjs - 在空白 Angulajs 中插入 td
问题描述
我是编程新手,但我坚持使用 Angularjs 中的一个项目,这是一项简单的任务,即在 html 表中添加一个没有任何数据的空白行,以便您可以注意到“质量”字段对组的分隔,因此,以更有序的方式查看它。
当质量数据发生变化时,必须插入行来分隔以下信息。明白了吗?
HTML 视图 在此处输入图像描述
我画了一条红线,我想在其中插入空白行。 在此处输入图像描述
解决方案
您可以做的是使用此解决方案pieces
对对象数组进行分组: https ://stackoverflow.com/a/14696535/9939798 。quality
您的控制器的示例代码:
function groupBy(arr, property) {
return arr.reduce(function (memo, x) {
if (!memo[x[property]]) { memo[x[property]] = []; }
memo[x[property]].push(x);
return memo;
}, {});
}
$scope.pieces = [
{ quality: "602P10D", status: "Dispatched" },
{ quality: "602P10D", status: "Dispatched" },
{ quality: "6025098", status: "Dispatched" },
{ quality: "6025098", status: "Dispatched" }
];
$scope.grouped = groupBy($scope.pieces, 'quality');
示例表标记:
<table>
<thead>
<tr>
<th>Quality</th>
<th>Status</th>
</tr>
</thead>
<tbody ng-repeat="pieces in grouped">
<tr ng-repeat="data in pieces">
<td>{{ data.quality }}</td>
<td>{{ data.status }}</td>
</tr>
<tr>
<td colspan="2"><!-- This is the separator --></td>
</tr>
</tbody>
</table>
在这里工作小提琴:https ://jsfiddle.net/75ez2nkw/1/
推荐阅读
- r - 如何使用 R 从大文本文件中提取几行选择?
- mongodb - 如果 MongoDB 服务器版本:4.2.9 和 MongoDB shell 版本 v4.4.1 不匹配,我应该担心吗?
- r - 有没有办法在插入符号 R 的模型中更改分类的阈值?
- mysql - MySQL:连接三个表并分组一列
- javascript - 当用户在 jQuery 中输入受限字符时,如何让 div 显示?
- amazon-web-services - AWS:在不同账户中使用 Kinesis Firehose 读取 Kinesis Stream 数据
- postgresql - 在 PostgreSQL 视图中包含一个 TIMESTAMP = NOW() 列
- javascript - 如何在javascript中将音频添加到10秒倒计时
- python - python嵌套while循环和日期时间
- python - Pygame 密钥约定