angularjs - Angular order Object by properties -


i have angular app consumes json api endpoint. json data arrives so:

tasks:

$scope.tasks = [ {id:23, title:'foo'}, {id:448, title:'bar'} ] 

but sake of accessing data within angular map th objects like:

$scope.tasks = { 23:{id: 23, title:'foo'}, 448:{id:23, title:'foo'} } 

this allows me pull out task instances , modify task instances using id only.

the consequence of have lost easy orderby methods of angular, though ng-repeat continues function expected.

so, question is, if want order list title or -title, how can achieved? there in angular accomplish or should roll own filter?

edit

so in template want this:

<div ng-repeat="task in tasks | orderby:'-title'">     <span>{{ task.title }}</span> </div> 

so orderby filter works if code in first format doesn't work if code mapped in second format.

why not write method pull out task based on given id, rather re-format response api , write own repeater directives?

function gettask(id) {     (var = 0; < $scope.tasks.length; i++) {         if ($scope.tasks[i].id == id)             return $scope.tasks[i];      } } 

the above task still binded $scope.tasks array, property changes make should reflected in view.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -