如何在对象数组中使用 ng-repeat?

How to use ng-repeat in array of objects?

你有什么想法吗?

我试着用 ng-repeat 制作一个数组数组,如下所示:

jsfiddle example

function MyCtrl($scope) {
    $scope.items = 
        [
         {'adam1': [{id:10, content:test1}, {id:11, content:test2},          
                    {id:12, content:test3}]}, 
         {'adam2': [{id:20, content:test4}, {id:21, content:test5},          
                    {id:30, content:test6}]}, 
         {'adam1': [{id:10, content:xxx}]}
         ];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<div ng-app ng-controller="MyCtrl">
    <ul>
        <li ng-repeat="(key, value) in items">{{key}}: {{value.content}}</li>
    </ul>
</div>

一种方法 (fiddle):

<div ng-repeat="item in items">
    <ul ng-repeat="(key, value) in item">
        <li ng-repeat="obj in value">{{obj.content}}</li>
    </ul>
</div>

那是说您可能需要重新排列结构以避免嵌套 ng-repeat

您分配变量的方法工作正常,但可能不像您期望的那样:updated jsfiddle

content 项将不可用,因为 value 是主数组中的每个对象;您需要循环遍历它们的属性(即 adamX 键)以获取嵌套数组。