关于angularjs:Angular orderBy子值

Angular orderBy sub value

我有ngRepeating的以下对象,希望通过" pricing.total"进行排序。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"data":{  
 "12654fcd":{  
    "sequenceNumber":"12654fcd",
    "directionInd":"OneWay",
    "journey":[  ],
    "pricing":{
         "total":"1200.79"
     },
    "breakdown":{  },
    "validatingCarrier":"DL"
  },
 "1eb562ab":{  
    "sequenceNumber":"1eb562ab",
    "directionInd":"OneWay",
    "journey":[  ],
    "pricing":{
         "total":"1400.80"
     },
    "breakdown":{  },
    "validatingCarrier":"DL"
  },
}

这是输出:

1
 

我的重复效果很好,但是我试图按price.total对输出进行排序,但没有成功。

我将如何去做? 甚至有可能实现对子值的排序?

干杯,


orderBy
- filter in module ng

Orders a specified array by the expression predicate. It is ordered
alphabetically for strings and numerically for numbers. Note: if you
notice numbers are not being sorted as expected, make sure they are
actually being saved as numbers and not strings.

排序依据仅适用于数组。 您的不是数组,而是它的对象。

将数据结构更改为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"data":[  
  {  
    "sequenceNumber":"12654fcd",
    "directionInd":"OneWay",
    "journey":[  ],
    "pricing":{
         "total":"1200.79"
     },
    "breakdown":{  },
    "validatingCarrier":"DL"
  },
  {  
    "sequenceNumber":"1eb562ab",
    "directionInd":"OneWay",
    "journey":[  ],
    "pricing":{
         "total":"1400.80"
     },
    "breakdown":{  },
    "validatingCarrier":"DL"
  },
]

$ scope.by_pricing_total = function(it){返回它。pricing.total}
然后
orderBy:by_pricing_total

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
angular.module('orderByExample', [])
  .controller('ExampleController', ['$scope',
    function($scope) {
      $scope.friends = [{
        name: 'John',
        phone: '555-1212',
        age: 10,
        data: {
          a: 57
        }
      }, {
        name: 'Mary',
        phone: '555-9876',
        age: 19,
        data: {
          a: 53
        }
      }, {
        name: 'Mike',
        phone: '555-4321',
        age: 21,
        data: {
          a: 51
        }
      }, {
        name: 'Adam',
        phone: '555-5678',
        age: 35,
        data: {
          a: 53
        }
      }, {
        name: 'Julie',
        phone: '555-8765',
        age: 29,
        data: {
          a: 52
        }
      }];

      $scope.getDataA = function(it) {
        console.log(it.data);
        return it.data.a;
      }
    }
  ]);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js">
Hello Plunker!

  <table class="friend">
    <tbody>
      <tr>
        <th>Name</th>
        <th>Phone Number</th>
        <th>Age</th>
      </tr>
      <tr ng-repeat="friend in friends | orderBy:getDataA">
        <td>{{friend.name}}</td>
        <td>{{friend.phone}}</td>
        <td>{{friend.age}}</td>
      </tr>
    </tbody>
  </table>