Javascript AngularJs-通过场地的度假村阵列
我有这样一个数组:Javascript AngularJs-通过场地的度假村阵列,javascript,angularjs,Javascript,Angularjs,我有这样一个数组: [Object,Object,Object]; 每个对象都有名为“rate”的属性。我只想用rate属性对这个对象进行排序 我的JS中有变量($scope.restaurants.data)。这就是这个变量的结构: Array[3] 0:Object ID:3 name:"bestRest" profile:"rest.png" rate:1 restaurantCitySlug:"NY" slug:"foo" __proto__:Object
[Object,Object,Object];
每个对象都有名为“rate”的属性。我只想用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
我的解释是:
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
试试这个
sortData = $filter('orderBy')(YOURDATA, 'rate');
试试这个
sortData = $filter('orderBy')(YOURDATA, 'rate');
您可以在控制器中使用
$filter
,如下所示
$scope.restaurants.data = $filter('orderBy')($scope.restaurants.data, 'rate');
您可以在控制器中使用
$filter
,如下所示
$scope.restaurants.data = $filter('orderBy')($scope.restaurants.data, 'rate');
就用普通的旧的
就用普通的旧的
您可以使用
orderBy
filter进行此操作。例如$filter('orderBy')(YOURDATA,'rate')
@Hadi我希望在我的控制器中而不是在HTML中进行此操作。您可以使用orderBy
过滤器进行此操作。例如$filter('orderBy')(YOURDATA,'rate')
@Hadi我希望在我的控制器中而不是在HTML中进行此操作。$.restaurants.data
,打字错误?$。餐厅。数据
,打字错误?