在ng-repeat中迭代对象或数组

bro*_*ock 8 angularjs angularjs-ng-repeat

我传入视图的JSON里面有对象和数组.例:

{ name: "test", projects: [ { name: "project1", tasks: "task1" } ] }
Run Code Online (Sandbox Code Playgroud)

使用ng-repeat,我可以说(key, value) in items并给出你期望的,每个键和对象或数组的字符串化版本.

是否存在迭代ng-repeat内的对象和数组的"最佳实践"?

bro*_*ock 17

刚跟进答案,我能够弄明白这一点.这比我意识到的要简单.刚刚为数组项使用了另一个ng-repeat.

<div class="container" ng-repeat="item in items">
<table class="table table-striped table-bordered table-condensed">
    <tr>
        <th class="span3">name</th>
        <td>{{ item.name }}</td>
    </tr>
    <tr>
        <th class="span3">accounts</th>
        <td>
            <ul ng-repeat="account in item.accounts">
                <li>username: {{ account.username }}</li>
                <li>password: {{ account.password }}</li>
            </ul>
        </td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)