1
我有數據很基本的NG-重複在一個表:角重複 - 動態性能
$scope.data = [ {
version: 1,
ID: 78,
name: "Bulk 61",
createdBy: "Master",
email: "[email protected]",
city: "New York",
state: "New York",
country: "Canada",
address: "123 street road",
type: "Something",
},
{
version: 2,
ID: 4,
name: "Bulk 1221",
createdBy: "Master22",
email: "[email protected]",
city: "New York22",
state: "New Yor22k",
country: "Canada2",
address: "123 str22eet road",
type: "Somet2hing",
}
];
事情是,我不知道該對象的屬性是什麼,因爲我將獲得的屬性名稱另一個對象:
$scope.properties = [
"name",
"type",
"ID",
"country",
"email"
];
所以,在現實中,根據我收到的屬性,它可能是item.country
而不是item.name
所以,如果我BUIL d在視圖中的表,它看起來像這樣:
<table>
<tr>
<th ng-repeat="property in properties">{{property}}</th>
</tr>
<tr ng-repeat="item in data">
<td>{{item.property[0]}}</td>
<td>{{item.property[1]}}</td>
<td>{{item.property[2]}}</td>
<td>{{item.property[3]}}</td>
<td>{{item.property[4]}}</td>
</tr>
</table>
是否可以做我想做的事?顯然,如果我知道屬性名稱,很容易將它放在視圖中,但在這種情況下,它取決於我從properties
對象收到的內容。
我創建了一個plnkr證明我想達到的目標:http://plnkr.co/edit/LImqZuLzcvKsbHUEOOrX?p=preview
非常感謝! – eHx 2015-03-02 19:47:43