Nic*_*ahn 7 angularjs ng-repeat angularjs-ng-repeat
更新:
在我的html页面上,我使用如下:
<section ng-repeat="template in templates">
<ng-include src="template"></ng-include>
</section>
Run Code Online (Sandbox Code Playgroud)
但问题是我需要特定顺序的特定文件,所以有没有办法控制顺序渲染的方式?
我试图通过一个对象来命令我该如何做到这一点,我在网上搜索后才发布它.
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>
Run Code Online (Sandbox Code Playgroud)
JLR*_*she 16
您不能将过滤器应用于普通对象,仅应用于数组.
你可以做的是在控制器中定义一个方法,将对象转换为数组:
$scope.templatesAry = function () {
var ary = [];
angular.forEach($scope.templates, function (val, key) {
ary.push({key: key, val: val});
});
return ary;
};
Run Code Online (Sandbox Code Playgroud)
然后筛选:
<li ng-repeat="prop in templatesAry() | orderBy:'-key'">
{{prop.key}}: {{prop.val}}
</li>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15091 次 |
| 最近记录: |