AngularJS / Repeat SubElement

时间:2014-08-12 06:58:25

标签: angularjs angularjs-ng-repeat

我有这样的元素构造:

elements = [{
    class: 'class1',
    subject: 'name1',
    students : [{ Name : Toto  } , {Name : Tata}]
}, {
    class: 'class2',
    subject: 'name2',
    students : [{ Name : Titi  } , {Name : Tutu}]
}];

我想在这样的公共表格中显示元素和学生,但我认为多重复制是不可能的?

<tr><td>class1</td></tr>
<tr><td>Toto</td></tr>
<tr><td>Tata</td></tr>

<tr><td>class2</td></tr>
<tr><td>Titi</td></tr>
<tr><td>Tutu</td></tr>

真实的代码......

<table class="table table-hover" ng-controller="actionController">
<thead>
    <tr>
        <th></th>
        <th>Commentaire</th>
        <th>Actions</th>
        <th>Visuel</th>
    </tr>
</thead>
<tbody>
        <tr ng-repeat="section in Sections" class="info">
            <td>{{section.label}}</td>
            <td></td>
            <td></td>
            <td></td>

       <tr ng-repeat="chapiter in section.chapiters">
            <td>{{chapiter.label}}</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
       </tr>
    </tbody>
</table>

我在这里找到解决方案: http://jsfiddle.net/nk3ta/

1 个答案:

答案 0 :(得分:2)

尝试使用ng-repeat-startng-repeat-end。在AngularJS v 1.2.21

中测试过
<table>
    <tr ng-repeat-start="item in elements">
        <td>{{item.class}}</td>
    </tr>
    <tr ng-repeat-end ng-repeat="s in item.students">
        <td>{{s.Name}}</td>
    </tr>
</table>

<强> Fiddle