AngularJS ng-repeat orderBy日期无效

时间:2022-12-02 18:09:38

I have a working ng-repeat, that I would like to order by descending date (newest items first).

我有一个正在工作的ng-repeat,我想按下个日期来订购(最新的项目)。

However, I can not seem to get it to work. I have double checked quoting, etc. I have tried orderBy:'createdate':reverse , orderBy:'article.createdate':reverse, and orderBy:'data.blog.article.createdate':reverse None seem to work.

然而,我似乎无法让它发挥作用。我反复检查过引用,等等。我试过orderBy: createdate:reverse, orderBy: article。createdate data.blog.article:反向,和orderBy:。反:似乎没有一个起作用。

This is my view:

这是我的观点:

<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>

Here is a sample of the data (converted to JSON from XML using X2JS):

下面是一个数据示例(使用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 个解决方案

#1


62  

The reverse argument should be a boolean value.

相反的参数应该是布尔值。

Assuming you don't have reverse set to true or false somewhere in your controller, you should replace

假设您的控制器中没有将反向集设置为true或false,那么您应该进行替换

orderBy:'createdate':reverse

with

orderBy:'createdate':true

Demo

演示

orderBy docs

orderBy文档

#1


62  

The reverse argument should be a boolean value.

相反的参数应该是布尔值。

Assuming you don't have reverse set to true or false somewhere in your controller, you should replace

假设您的控制器中没有将反向集设置为true或false,那么您应该进行替换

orderBy:'createdate':reverse

with

orderBy:'createdate':true

Demo

演示

orderBy docs

orderBy文档