如何在ng-repeat中以数字方式命令整数?

时间:2014-12-18 15:09:11

标签: angularjs

我正在显示id排序的列表,其中包含以下代码:

            <dl class="dl-horizontal" ng-repeat="projectManager in projectManagers| orderBy: 'id'">
                <dt>{{projectManager.id}}</dt>
                <dd>{{projectManager.givenname}} {{projectManager.surname}}</dd>
            </dl>

但这些想法按字母顺序排列:

1
11
13
21
25
3
35

如何以数字方式订购?

1 个答案:

答案 0 :(得分:1)

您可以将自定义功能传递给orderBy

<dl class="dl-horizontal" ng-repeat="projectManager in projectManagers| orderBy: parseLikeAPro">

并在控制器中:

 $scope.parseLikeAPro = function(pm) {
    return pm.id | 0;
  }

http://plnkr.co/edit/xZx9dNFvryLptgPv6SiZ?p=preview

docs