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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -