javascript - AngularJs - resort array via a field -


i have array :

[object,object,object]; 

each object has property name "rate". want sorting object rate property.

i have variable ($scope.restaurants.data) in js. , structure of variable:

array[3] 0:object   id:3   name:"bestrest"   profile:"rest.png"   rate:1   restaurantcityslug:"ny"   slug:"foo"   __proto__:object 1:object   id:7   name:"bestres3t"   profile:"rest7.png"   rate:0   restaurantcityslug:"ny"   slug:"fo4o"   __proto__:object 2:object   id:7   name:"bestr242es3t"   profile:"re3st7.png"   rate:2   restaurantcityslug:"ny"   slug:"fo244o"   __proto__:object 

and exeption :

array[3] 0:object   id:7   name:"bestres3t"   profile:"rest7.png"   rate:0   restaurantcityslug:"ny"   slug:"fo4o"   __proto__:object 1:object   id:3   name:"bestrest"   profile:"rest.png"   rate:1   restaurantcityslug:"ny"   slug:"foo"   __proto__:object 2:object   id:7   name:"bestr242es3t"   profile:"re3st7.png"   rate:2   restaurantcityslug:"ny"   slug:"fo244o"   __proto__:object 

you can use $filter orderby in controller below

  $scope.restaurants.data = $filter('orderby')($scope.restaurants.data, 'rate'); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -