javascript - How to sort this object by name in angular -
my client needs angular js app, app based on api, of app that's running. 1 of apis, returns json structured this:
{ "groups":{ "60":{ "name":"history" }, "74":{ "name":"discover our offers" }, "109":{ "name":"relaxing" } } }
so fetched data on controller way:
$http({method: 'get', url: resturl}). then(function(response) { $scope.poi_groups = response.data.groups; });
and display on view:
<ul class="content-menu"> <li ng-repeat="(key, value) in poi_groups"> <div><a ng-href="/poi/data/{{ key }}">{{ value.name }}</a></div> </li> </ul>
what i've been struggling ordering items name, right being displayed way returned on json. how can like:
(...) <li ng-repeat="(key, value) in poi_groups | orderby: value.name"> (...)
this structure isn't appropriate angularjs, either :
- do in .then method
- write own filter
map object in new 1 in .then method make :
[{ value:'60', name:'history' }, { .... }]
then can use angular filtering.
Comments
Post a Comment