且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ng-repeat 没有按预期工作

更新时间:2023-11-04 10:02:04

你可以试试

<tr ng-repeat-start="obj 中的父级"><td>{{parent.name}}</td></tr><tr ng-repeat="child in parent.children"><td>{{child.name}}</td></tr><tr ng-repeat-end=""><tr/>

Below object should generate table rows for parent and child objects under one table(as siblings). how it can be, I used ng-repeat-start but no use. I need it for equal alignments.

[
{'name':'parent1','children':[{'name':'child1'},{'name':'child2'}]},
{'name':'parent2','children':[{'name':'child1'},{'name':'child2'}]}
......
]
<table>
<tr ng-repeat="parent in obj">
<td>{{parent.name}}</td>
</tr>
<tr ng-repeat="child in parent.children">
<td>{{child.name}}</td>
</tr>
...........

Table should generate like below:

<table>
<tr>
<td>Parent1</td>
</tr>
<tr>
<td>child1</td>
</tr>
<tr>
<td>child2</td>
</tr>
<tr>
<td>Parent2</td>
</tr>
<tr>
<td>child1</td>
</tr>
<tr>
<td>child2</td>
</tr>
......
</table>

You may try

<table>
    <tr ng-repeat-start="parent in obj">
        <td>{{parent.name}}</td>
    </tr>
    <tr ng-repeat="child in parent.children">
        <td>{{child.name}}</td>
    </tr>
    <tr ng-repeat-end="">
    <tr/>
</table>