ng-repeat 数组的关联数组?
ng-repeat over an associative array of arrays?
我正在尝试使用数组的关联数组在 angular 中设置嵌套重复。例如我有这样的结构:
集合['key1'] = [obj1,obj2,obj3,obj4];
集合['key2'] = [obj5,obj6,obj7];
我想要一个结构如下的视图:
<div ng-repeat="collection in collections">
<h4>{{collection.id}}</h4>
<div ng-repeat="item in collection">
<span>{{item.name | item.value}}</span>
</div>
</div>
但是,一旦我添加了 ng-repeat="collection in collections",我的视图就变成了空白。在 angular 中有没有办法做到这一点,或者如果我想以这种方式循环它,我是否需要更新我存储数据的方式?谢谢
只是举例说明如何使用它
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.school = {
classes:[
{name:"Class 1", peoples:["Peter","Sue","Marc"]},
{name:"Class 2", peoples:["John","Edward","Sara"]}
]
}
});
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="class in school.classes">
<h4>{{class.name}}</h4>
<div ng-repeat="person in class.peoples">
<label>{{person}}</label>
</div>
<br>
</div>
</div>
</body>
</html>
我正在尝试使用数组的关联数组在 angular 中设置嵌套重复。例如我有这样的结构:
集合['key1'] = [obj1,obj2,obj3,obj4];
集合['key2'] = [obj5,obj6,obj7];
我想要一个结构如下的视图:
<div ng-repeat="collection in collections">
<h4>{{collection.id}}</h4>
<div ng-repeat="item in collection">
<span>{{item.name | item.value}}</span>
</div>
</div>
但是,一旦我添加了 ng-repeat="collection in collections",我的视图就变成了空白。在 angular 中有没有办法做到这一点,或者如果我想以这种方式循环它,我是否需要更新我存储数据的方式?谢谢
只是举例说明如何使用它
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.school = {
classes:[
{name:"Class 1", peoples:["Peter","Sue","Marc"]},
{name:"Class 2", peoples:["John","Edward","Sara"]}
]
}
});
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="class in school.classes">
<h4>{{class.name}}</h4>
<div ng-repeat="person in class.peoples">
<label>{{person}}</label>
</div>
<br>
</div>
</div>
</body>
</html>