给定以下模型:
[{categoryName: "category1", items:[{name:"item1.1"}{name:"item1.2"},...]},
{categoryName: "category2", items:[{name:"item2.1"},...]},...]
我想创建这个表:
<table>
<tr>
<th>category1</th>
</tr>
<tr>
<td>item1.1</td>
</tr>
<tr>
<td>item1.2</td>
</tr>
...
<tr>
<th>category2</th>
</tr>
<tr>
<td>item2.1</td>
</tr>
...
</table>
你会如何使用 angularjs 指令来完成它?
最佳答案
嵌套重复和新的 ng-repeat-start
/ng-repeat-end
和 记住 <table>
没问题有很多 body 和头:
<table>
<thead ng-repeat-start="x in data">
<tr><th>{{x.categoryName}}</th></tr>
</thead>
<tbody ng-repeat-end>
<tr ng-repeat="y in x.items">
<td>{{y.name}}</td>
</tr>
</tbody>
</table>
相关 fiddle :http://jsfiddle.net/kGZt8/
文档:ngRepeat
关于javascript - angularjs 表 : tr with category using ng-repeat with list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21134384/