programing

AngularJs ng-repeat orderBy date가 작동하지 않음

showcode 2023. 4. 5. 22:28
반응형

AngularJs ng-repeat orderBy date가 작동하지 않음

내림차순으로 주문하고 싶은 ng-repeat이 있습니다(최신품부터 주문).

하지만 잘 안 될 것 같아요.견적서 등을 다시 확인했습니다.난 시도했다.orderBy:'createdate':reverse,orderBy:'article.createdate':reverse,그리고.orderBy:'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>

다음으로 데이터(X2J를 사용하여 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"
            }
        ]
    }
}

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

컨트롤러의 어딘가에서 true 또는 false로 역설정이 되어 있지 않은 경우,

orderBy:'createdate':reverse

와 함께

orderBy:'createdate':true

데모

orderBy 문서

언급URL : https://stackoverflow.com/questions/24048590/angularjs-ng-repeat-orderby-date-not-working

반응형