angularjs – ng-repeat orderBy对象
发布时间:2020-12-17 10:19:26 所属栏目:安全 来源:网络整理
导读:更新: 在我的html页面上,我使用如下: section ng-repeat="template in templates" ng-include src="template"/ng-include /section 但问题是我需要特定顺序的特定文件,所以有没有办法控制顺序渲染的方式? 我试图通过一个对象来命令我该如何做到这一点,我
更新:
在我的html页面上,我使用如下: <section ng-repeat="template in templates"> <ng-include src="template"></ng-include> </section> 但问题是我需要特定顺序的特定文件,所以有没有办法控制顺序渲染的方式? 我试图通过一个对象来命令我该如何做到这一点,我在网上搜索后才发布它. function MyCtrl($scope) { $scope.templates = { template_address: "../template/address.html",template_book: "../template/book.html",template_create: "../template/create.html" }; <div ng-app ng-controller="MyCtrl"> <ul> <li ng-repeat="(name,path) in templates">{{name}}: {{path}}</li> </ul> </div> http://jsfiddle.net/abuhamzah/6fbpdm9m/
您不能将过滤器应用于普通对象,only to arrays.
你可以做的是在控制器中定义一个方法,将对象转换为数组: $scope.templatesAry = function () { var ary = []; angular.forEach($scope.templates,function (val,key) { ary.push({key: key,val: val}); }); return ary; }; 然后筛选: <li ng-repeat="prop in templatesAry() | orderBy:'-key'"> {{prop.key}}: {{prop.val}} </li> Example (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |