angularjs – 如何在不创建过滤器的情况下反转角度js中的数组
发布时间:2020-12-17 08:53:04 所属栏目:安全 来源:网络整理
导读:我在控制器中有一个数组,如下所示 function FooController($scope) { $scope.items = ["a","b","c"];} 我用ng-repeat来显示项目中的数据, div ng-app div ng-controller="FooController" ul ng-repeat="item in items" li{{item}}/li /ul /div/div 我把结果
我在控制器中有一个数组,如下所示
function FooController($scope) { $scope.items = ["a","b","c"]; } 我用ng-repeat来显示项目中的数据, <div ng-app> <div ng-controller="FooController"> <ul ng-repeat="item in items"> <li>{{item}}</li> </ul> </div> </div> 我把结果作为a,b,c顺序.我想以相反的顺序显示它.这意味着c,a不改变其在控制器中的顺序或不创建过滤器.怎么做?
为了避免编写自定义过滤器,我建议您使用以下语法:
<ul ng-repeat="item in items | orderBy:'-toString()'"> 文档假设您对一个对象数组进行排序,但在您的情况下,只有简单的字符串. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |