【发布时间】:2016-09-26 03:22:00
【问题描述】:
我正在构建我的第一个 Angular 应用程序。
我正在使用工厂服务从 API 返回一些 JSON 数据,其中包括足球比赛装置。
我想按日期分组,但不考虑时间。 JSON日期字符串的格式为“2016-06-10T19:00:00Z”
我已经成功地在我的 ng-repeat 上使用了 groupBy,这很好用 - 唯一的问题是 - 它还考虑了时间,因此不会对同一天在不同 KO 时间的 2 场比赛进行分组。
我的 JSON 对象是这样的,我将它分配给我的控制器中名为 fixtures.list 的数组:
"fixtures":[
{
"_links":{
"self":{
"href":"http://api.football-data.org/v1/fixtures/149855"
},
"soccerseason":{
"href":"http://api.football-data.org/v1/soccerseasons/424"
},
"homeTeam":{
"href":"http://api.football-data.org/v1/teams/773"
},
"awayTeam":{
"href":"http://api.football-data.org/v1/teams/811"
}
},
"date":"2016-06-10T19:00:00Z",
"status":"TIMED",
"matchday":1,
"homeTeamName":"France",
"awayTeamName":"Romania",
"result":{
"goalsHomeTeam":null,
"goalsAwayTeam":null
}
},
...
我的角度模板是这样的:
http://plnkr.co/edit/R4qjDfyKhefDOaHmleJv?p=preview
我的控制器:
function FixturesController (EurosService) {
var ctrl = this;
ctrl.list = [];
function getFixtures () {
EurosService
.retrieveFixtures()
.then( function (response) {
ctrl.list = response;
});
}
getFixtures();
}
angular
.module('app')
.controller('FixturesController', FixturesController)
对此表示赞赏。最好的方法是什么?谢谢。
【问题讨论】:
-
你能分享一下你如何在 ng-repeat 上使用
groupBy的代码吗? -
现在添加了 plnkr 的链接。在 stackoverflow 上有点菜鸟
标签: javascript angularjs json