/ / AngularJS ng-repeat order Por fecha no funciona - json, angularjs

AngularJS ng-repeat orderBy date no funciona - json, angularjs

Tengo una repetición ng que me gustaría ordenar por fecha descendente (primero los elementos más nuevos).

Sin embargo, parece que no puedo hacer que funcione. He revisado las citas, etc. He intentado orderBy:"createdate":reverse , orderBy:"article.createdate":reversey orderBy:"data.blog.article.createdate":reverse Ninguno parece funcionar.

Esta es mi opinión:

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

Aquí hay una muestra de los datos (convertidos a JSON desde XML usando X2JS):

{
"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"
}
]
}
}

Respuestas

62 para la respuesta № 1

los reverse El argumento debe ser un valor booleano.

Suponiendo que no tiene reversa establecida en verdadero o falso en algún lugar de su controlador, debe reemplazar

orderBy:"createdate":reverse

con

orderBy:"createdate":true

Manifestación

orden Por documentos