gpt4 book ai didi

javascript - AngularJs - 通过字段的度假村数组

转载 作者:行者123 更新时间:2023-11-28 17:49:59 26 4
gpt4 key购买 nike

我有一个像这样的数组:

[Object,Object,Object];

每个对象都有名为“rate”的属性。我想要的只是使用速率属性对这个对象进行排序。

我的 JS 中有变量 ($scope.restaurants.data)。这是该变量的结构:

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

我的异常(exception)是:

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

最佳答案

您可以在 Controller 中使用 $filter orderBy 如下

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

关于javascript - AngularJs - 通过字段的度假村数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45779609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com