2014-06-04 3 views
28

날짜가 내림차순으로 주문하고 싶은 ng-repeat가 있습니다 (가장 최근 항목부터).AngularJS ng-repeat orderBy 날짜가 작동하지 않습니다.

그러나 나는 제대로 작동하지 않는 것 같습니다. 인용문 등을 두 번 확인했습니다. 시도했습니다. orderBy:'createdate':reverse, orderBy:'article.createdate':reverseorderBy:'data.blog.article.createdate':reverse 아무 것도 작동하지 않는 것 같습니다.

다음
<article data-ng-if="article.id == post || post===NULL" data-ng-repeat="article in data.blog.article | orderBy:'createdate':reverse | slice:currentPage*pageSize:currentPage+1*pageSize"> 
    <h2 class="blog-post-title"> 
     <a href="#!/blog/{{article.id}}" title="Permalink to {{article.title.__cdata}}">{{article.title.__cdata}}</a> 
    </h2> 
    <span class="blog-post-meta">Posted on {{article.createdate | date:'MMMM dd, yyyy h:mma'}} by {{article.author}}</span> 
    <div class="blog-post-content" ng-bind-html="article.content.__cdata">{{article.content.__cdata}}</div> 
</article> 

이 (X2JS를 사용하여 XML에서 JSON 변환) 데이터의 샘플입니다 :

{ 
    "blog": { 
     "article": [ 
      { 
       "id": "1", 
       "author": "eat-sleep-code", 
       "title": { 
        "__cdata": "The first article." 
       }, 
       "content": { 
        "__cdata": "\n  This is my first article in my test site.\n  " 
       }, 
       "createdate": "2014-05-09" 
      }, 
      { 
       "id": "2", 
       "author": "eat-sleep-code", 
       "title": { 
        "__cdata": "The second article." 
       }, 
       "content": { 
        "__cdata": "\n  This is my second article in my test site. This article's create date is actually earlier.\n  " 
       }, 
       "createdate": "2014-05-08" 
      } 
     ] 
    } 
} 
+1

때를 함께

orderBy:'createdate':reverse 

을 교체해야합니다 일하지 않는다고 말하면서, 무슨 일이 일어나고있는거야? 콘솔 오류가 있습니까? 그들은 단지 올바른 순서로 있지 않습니까? –

+0

콘솔 오류가 전혀 없습니다. 올바른 순서가 아닙니다. 아, 또한 제거하려고 시도 : orderBy에서 반대 그냥 문제가 아니 었는지 확인합니다. 변경 없음. –

+0

이 토론의 참고 자료 http://stackoverflow.com/questions/19876116/angular-orderby-date/25658846#25658846 – MDT

답변

62

reverse 인수는 부울 값이어야합니다

내이다.

는 당신이 역 컨트롤러에서 참 또는 거짓 어딘가로 설정이없는 가정하면, 당신은

orderBy:'createdate':true 

Demo

orderBy docs

+0

Thanks, saved saved 내 하루 –

+4

이 경우 AngularJS 문서는 멋지게 모호합니다. 간단한 정적 리버스의 예는 여기에 대해 묻지 않습니다. 그리고 제공하는 샘플에서 데모 변수는 키워드 ('reverse')와 동일하게 이름이 지정되어 사람들이이 두 가지를 혼동합니다. 우수한! – ryascl

+1

이제 orderBy : '- createdate'를 사용할 수도 있습니다. –

관련 문제