AngularJS按嵌套值的对象数组排序

AngularJS按嵌套值的对象数组排序,angularjs,Angularjs,我有这样一个对象数组: $scope.sortableItems = [ { name: 'Blue Shirt', fields: {Price: 20} }, { name: 'Pink Shirt', fields: {Price: 80}, }, { name: 'Orange Shirt', fields: {Price: 10}, } ] 我需要创建一个ng repeat字段,该字段可以根据从低到高或从高到低的

我有这样一个对象数组:

$scope.sortableItems =
[
  {
    name: 'Blue Shirt',
    fields: {Price: 20}
  },
  {
    name: 'Pink Shirt',
    fields: {Price: 80},
  },
  {
    name: 'Orange Shirt',
    fields: {Price: 10},
  }
]
我需要创建一个
ng repeat
字段,该字段可以根据从低到高或从高到低的价格对产品进行排序

我试过这个:

.product(ng-repeat="item in sortableItems | orderBy:fields.Price")
但没有效果


此外,我还有另一个变量
$scope.sortFunction
,它可以等于
Price:Low-High
Price:High-Low
最终结果需要检测
$scope.sortFunction
的值,并根据字符串的值进行排序。不知道如何使用
ng repeat

来实现这一点,您可以创建一个返回价格的函数,并在orderBy中使用该函数

js

html

{{item.fields['Price']}
order by采用第二个布尔值,可用于asc/desc排序


您可以创建一个返回价格的函数,并在orderBy中使用该函数

js

html

{{item.fields['Price']}
order by采用第二个布尔值,可用于asc/desc排序

  $scope.getPrice = function(item){
    return item.fields['Price'];
  }
<div ng-repeat="item in sortableItems | orderBy:getPrice:false">{{item.fields['Price']}}</div>