我正在使用Angular JS来显示JSON get请求中的项目列表。
我能够检索这些项目,但我无法以正确的顺序显示它们而不重复。
我的JSON文件如下:
[
{
"id":"32",
"competiton":"série1",
"game":"A- B"
},
{
"id":"33",
"competiton":"série1",
"game":"C - D"
}
]
这是我检索项目的代码:
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://myserver.com/matches?date=2015-05-18")
.success(function (response) {
$scope.matches = response;
for (var i = 0; i < response.length; i++) {
setName($scope.matches, i);
}
});
var setName = function (matches, index) {
$http.get("http://myserver.com/ofc/competitions/" + matches[index].idCompetition)
.success(function (response) {
matches[index].competition = response.name;
$scope.competitions[index] = response.name;
});
}
});
以下是我如何展示它们:
<div ng-controller="customersCtrl">
<div class="list">
<div class="item item-divider" ng-repeat="m in matches">
{{ m.competition}}
</div>
<a class="item" href="#" ng-repeat="m in matches">
{{ m.game }}
</a>
</div>
</div>
项目如下:
SérieA
SérieA
A - B
C - D
我想向他们展示:
SérieA
A - B
C - D. ......等等。
答案 0 :(得分:1)
使用“unique”:
<div class="item item-divider" ng-repeat="m in matches | unique:'competition'">
{{ m.competition}}
</div>