2015-02-04 20 views
0

我試圖篩選此JSON所以只顯示當前時間起條目:篩選由當前的日期/時間數據angularjs

JSON http://www.football-data.org/teams/354/fixtures/?callback=JSON_CALLBACK

HTML

<tr ng-repeat="fixture in fixtures.fixtures | greaterThan:fixture.date:date"> 
     <td>{{$index + 1}}</td> 
     <td>{{teamName(fixture.awayTeam)}}</td> 

控制器

.controller('fixturesController', function($scope, $routeParams, footballdataAPIservice) { 
     $scope.id = $routeParams.id; 
     $scope.fixtures = []; 
     $scope.date = new Date(); 

     footballdataAPIservice.getFixtures($scope.id).success(function (response) { 
      $scope.fixtures = response; 
     }); 


}); 

FILTER

angular.module('PremierLeagueApp', []) 

    .filter('greaterThan', function() { 
      return function (actualDate, comparisonDate) { 
       return Date(actualDate) > Date(comparisonDate); 
      }; 
     }); 

這不適合我,任何人看到爲什麼不呢?

回答

0

你的問題似乎是在日期比較。

嘗試將其更改爲:

return actualDate > new Date(comparisonDate); 

因爲actualDate是一個js Date對象,而comparisonDate距離JSON字符串。

0

我想你想要返回更大的日期,而不是實際日期是否大於比較日期。我對麼?

無論如何here是一個類似於你的問題。使用日期時間對象解決您的比較問題。

+0

是的,日期晚於當前日期的條目 – user1937021