필터

2015-02-04 7 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; 
     }); 


}); 

필터

angular.module('PremierLeagueApp', []) 

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

이것은 나를 위해 작동하지 않습니다.

답변

0

날짜 비교에 문제가있는 것 같습니다.

가로 변경 시도 : comparisonDate는 JSON에서 불과 문자열 인 반면 JS Date 객체가

return actualDate > new Date(comparisonDate); 

actualDate 때문이다.

0

실제 날짜가 비교 날짜보다 큰지 여부가 아니라 더 큰 날짜를 반환하고 싶습니다. 나 맞아?

아무튼 here은 (는) 당신과 비슷한 문제입니다. 날짜 시간 객체로 작업하면 비교 문제가 해결됩니다.

+0

예, 현재 날짜보다 늦은 날짜가있는 항목 – user1937021