问题描述
我有一张带有 ng-repeat 的表格。我想要的只是在 ng-repeat 中只显示一次该值。
我在 tr 中的 ng-repeat
<tr ng-repeat="xx in results " >
<tr>{{xx.id}}</tr>
<tr>{{xx.invoicenumber}}</tr>
</tr>
这是我的桌子
ID | INVOICE# |
---|---|
1 | 112 |
1 | 113 |
1 | 114 |
2 | 115 |
2 | 116 |
期望输出
ID | INVOICE# |
---|---|
1 | 112 |
113 | |
114 | |
2 | 115 |
116 |
解决方法
@SprakenDude ,您能否与我们分享有关您接收数据的方式和结构的详细信息?
,<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<table>
<tr>
<td>Id</td>
<td>Invoice Number</td>
</tr>
<tr ng-repeat="xx in results " >
<td>{{printXXId(xx.id)}}</td>
<td>{{xx.invoicenumber}}</td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp',[]);
app.controller('myCtrl',function($scope) {
$scope.preid=-1;
$scope.printXXId=function(id){
return $scope.preid==id?'':$scope.preid=id;
}
$scope.results=[
{
id:1,invoicenumber:112
},{
id:1,invoicenumber:113
},invoicenumber:114
},{
id:2,invoicenumber:115
},invoicenumber:116
},]
});
</script>
</body>
</html>