ng-repeat排序问题

<ul ng-repeat="x in data | orderBy:'-time'">
     <li>姓名:{{x.name}},时间:{{x.time}}</li>
 </ul>
<script>
    var app = angular.module("myApp", []);
    app.controller('Controller', function ($scope) {
        $scope.data=[{name:'ad',id:'01',time:'2017-4-06'},
                  {name:'zx',id:'02',time:'2017-4-05'},
                 {name:'lu',id:'02',time:'2017-5-17'}
        ]
    })
</script>

  按时间降序排。在字段名前加个“-”号即可。(个人觉得这个方法比较好)

 

方法二:

<ul ng-repeat="x in data | orderBy:x.time:'desc'">
<li>姓名:{{x.name}},时间:{{x.time}}</li>
</ul>
这个在百度上查到的,但有点问题,感觉不是很好,但有时候也是一种方法
posted @ 2017-05-24 09:27  liucong2016  阅读(3890)  评论(0编辑  收藏  举报