json - AngularJS ng-repeat orderBy date 不起作用

我有一个正常工作的 ng-repeat,我想按日期降序排序(最新项目优先)。

但是,我似乎无法让它工作。我仔细检查了引用等。我尝试过 orderBy:'createdate':reverseorderBy:'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"
            }
        ]
    }
}

最佳答案

reverse 参数应该是一个 bool 值。

假设您没有在 Controller 中的某处将 reverse 设置为 true 或 false,您应该替换

orderBy:'createdate':reverse

orderBy:'createdate':true

Demo

orderBy docs

https://stackoverflow.com/questions/24048590/

相关文章:

c# - 如何在 asp.net web api 中返回 json 错误消息?

json - 使用 Elasticsearch 搜索多个字段

java - JSON 和 BSON 哪个更轻量级?

java - 反序列化时忽略属性

eclipse - 如何在 Eclipse 中安装和使用 JSON 编辑器?

php - 如何使用 PHP 更新/编辑 JSON 文件

javascript - 如何 JSON 化 javascript 对象的属性

php - UTF-8 字符编码之战 json_encode()

.net - 在 .NET 中缩小缩进的 JSON 字符串

c# - 如何使JSON.NET忽略对象关系?