Angularjs ng重复李';基于嵌套数据,但不嵌套li';s
这是我的数据结构:Angularjs ng重复李';基于嵌套数据,但不嵌套li';s,angularjs,Angularjs,这是我的数据结构: headings = [ {name:'H1', items: ['a', 'b', 'c']}, {name:'H2', items: ['d', 'e', 'f']} ]; 我想做到这一点: <li ng-repeat="heading in headings" class="heading">{{ heading.name }}</li> <li ng-repeat="item in heading">{{ item.nam
headings = [
{name:'H1', items: ['a', 'b', 'c']},
{name:'H2', items: ['d', 'e', 'f']}
];
我想做到这一点:
<li ng-repeat="heading in headings" class="heading">{{ heading.name }}</li>
<li ng-repeat="item in heading">{{ item.name }}</li>
您可以使用附加元素包装lis,并在该元素上放置ng repeat。如果列表中没有其他li项,只需将ng repeat放在列表中:
<ul ng-repeat="heading in headings">
<li class="heading">{{ heading.name }}</li>
<li ng-repeat="item in heading.items">{{ item }}</li>
</ul>
- {{heading.name}
- {{item}
有关可运行的示例,请参见此。您可以使用附加元素包装lis,并在该元素上放置ng repeat。如果列表中没有其他li项,只需将ng repeat放在列表中:
<ul ng-repeat="heading in headings">
<li class="heading">{{ heading.name }}</li>
<li ng-repeat="item in heading.items">{{ item }}</li>
</ul>
- {{heading.name}
- {{item}
有关可运行的示例,请参见此。您可以将它们展平:
$scope.$watch('headings', function(headings) {
$scope.flattened = [];
angular.forEach(headings, function(heading) {
angular.forEach(heading.items, function(item) {
$scope.flattened.push({
heading: heading,
item: item
});
});
});
});
然后在HTML中:
<li ng-repeat="flat in flattened">{{flat.item.name}}</li>
{{flat.item.name}
您可以将它们展平:
$scope.$watch('headings', function(headings) {
$scope.flattened = [];
angular.forEach(headings, function(heading) {
angular.forEach(heading.items, function(item) {
$scope.flattened.push({
heading: heading,
item: item
});
});
});
});
然后在HTML中:
<li ng-repeat="flat in flattened">{{flat.item.name}}</li>
{{flat.item.name}
您可以使用ng repeat start
和ng repeat end
:
<li ng-repeat-start="heading in headings" class="heading">{{ heading.name }}</li>
<li ng-repeat="item in heading.items" ng-repeat-end>{{ item }}</li>
{{{heading.name}
{{item}
ng repeat start
重复所有操作,直到并包括具有ng repeat end
的元素 您可以使用ng repeat start
和ng repeat end
:
<li ng-repeat-start="heading in headings" class="heading">{{ heading.name }}</li>
<li ng-repeat="item in heading.items" ng-repeat-end>{{ item }}</li>
{{{heading.name}
{{item}
ng repeat start
重复所有操作,直到并包括具有ng repeat end
的元素 是否要生成带有标题的表?能否给出在ng repeat
完成后要生成的HTML标记的示例?是否要生成带有标题的表?能否给出在ng repeat
完成后要生成的HTML标记的示例?