AngularJS:orderBy - string&数组不一样

时间:2015-01-31 08:34:16

标签: angularjs multiple-columns angularjs-orderby

我有一系列用户:

$scope.users = [
  {name: 'Anh', age: 10},
  {name: 'Ánh', age: 10},
  {name: 'Ba' , age: 10}
]

当我使用orderBy:'name'时,结果为:

  1. ANH
  2. 的Ba
  3. 但是当我使用多个字段orderBy:['name','age']时,结果会有所不同:

    1. 的Ba
    2. ANH
    3. 等待你的帮助!

1 个答案:

答案 0 :(得分:0)

试试这个..

var app = angular.module('filterSample', []);
app.controller('filterCtrl', function ($scope) {

  $scope.data = {
    messages: ['first', 'second', '3rd', 'fourth', 'fifth']
  }

  $scope.startsWith = function (actual, expected) {
    var lowerStr = (actual + "").toLowerCase();
    return lowerStr.indexOf(expected.toLowerCase()) === 0;
  }
});

和html为

<ul border="1px" ng-repeat="msg in data.messages | filter:search:startsWith">
      <li>{{msg}}</li>
    </ul>

或查看此plunkr - http://plnkr.co/edit/gcVYfZXTqsDU1Z7REU2I?p=preview