Вопрос

I'm getting a json response from an external API in such format:

catno: "DNO 2CD, DOMUS02CD"
country: "US"
format: "CD, Album"
id: 14124
label: "Domino USA, Domino USA"
released: "2001-10-09"
resource_url: "http://api.discogs.com/releases/14124"
status: "Accepted"
thumb: "http://api.discogs.com/image/R-150-14124-001.gif"
title: "Pause"

As I'm attempting to show only the year and the response comes back as a string, I'm using the Truncate module to show only the first 4 characters, but when I attempt to order the ng-repeat by version.released, it doesn't work, as the array comes back with random order and the orderby will just display the results in the same order they get dumped.

 <li class="row" ng-show="versions" ng-repeat="version in versions | filter: \'!file\' | orderBy: version.released"> \
     <div class="col-md-1">{{(version.released | release:4) || \'-----\'}}</div> \
 </li> \

Any tip on how to properly write the orderby?

I thought that maybe it'd be a good idea to just write a custom filter inside the "release" truncate filter, but I dunno if that's actually the proper way to go.

Any thoughts?

Это было полезно?

Решение

Specify the property to sort by as a string (remembering to escape the ' since this is a part of a string template):

<li ng-repeat="version in versions | filter: \'!file\' | orderBy: \'released\'">

Here is a working demo: http://plnkr.co/In3neXDQ6wXgc8ZI2hkX

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top