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