我在表格中有一个非常基本的重复数据:
$scope.data = [ {
version: 1,
ID: 78,
name: "Bulk 61",
createdBy: "Master",
email: "email@email.com",
city: "New York",
state: "New York",
country: "Canada",
address: "123 street road",
type: "Something",
},
{
version: 2,
ID: 4,
name: "Bulk 1221",
createdBy: "Master22",
email: "ema2il@email.com",
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
因此,如果我在视图中构建表,它将如下所示:
<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
答案 0 :(得分:4)
当然,只需设置第二个转发器来迭代属性名称并使用括号表示法:
<tr ng-repeat="item in data">
<td ng-repeat="prop in properties">{{item[prop]}}</td>
</tr>
您可能想要检查当前迭代的item