我想要做的是創建一個表格,我將在其中提供表格的內容,標題(thead)和主體。內容將是一個JSON對象,標題和主體屬性將是數組。AngularJS:如何在HTML中使用兩個ng-repeat來顯示對象值
什麼我迄今所做的:
在控制器數據(MainCtrl)
$scope.people = [
{
"name": "Adam",
"age": "21",
"town": "IL",
"work": "Manager"
},
{
"name": "Christina",
"age": "25",
"town": "MS",
"work": "Designer"
},
{
"name": "Luke",
"age": "22",
"town": "VA",
"work": "Developer"
}
]
$scope.heads = ["Name", "Age", "Work"]
$scope.attrs = ["name", "age", "work"]
我設法顯示標題,但問題是{{ person.attr }}
。我無法訪問屬性。
<table>
<thead>
<tr>
<th ng-repeat="head in heads">{{ head }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in people">
<td ng-repeat="attr in attrs"> {{ person.attr }} </td>
</tr>
</tbody>
</table>
我想實現的是:
Name Age Work
-----------------------------------
Adam 21 Manager
Christina 25 Designer
Luke 22 Developer
工作正常!如何訪問是兩個和三個層次深的數據,如 ' { 「名」:「盧克」, 「時代」:「22」, 地方:{「鎮」:「VA」}, 「work」:「Developer」 } ' –
person ['places'] ['town']是應該如何做的一個例子。 – Dij