[英]Making Nested ng-repeat in AngularJS dynamic
I'm trying to implement a table using ng-repeat for the following data : 我正在尝试使用ng-repeat为以下数据实现表:
[{
"Name": "Alfreds Futterkiste",
"City": "Berlin",
"Country": "Germany"
}, {
"Name": "Berglunds snabbköp",
"City": "Luleå",
"Country": "Sweden"
}]
Here is my AngularJS code : 这是我的AngularJS代码:
<table>
<tr ng-repeat="d in stuff">
<td>
{{d.Name}}
</td>
<td>
{{d.Country}}
</td>
<td>
{{d.City}}
</td>
</tr>
</table>
The above code works fine but the number of td
has been hard coded. 上面的代码可以正常工作,但是td
的数量已经过硬编码。 Is there any way to make it dynamic. 有什么方法可以使其动态化。
Add a second ng-repeat
to your table: 向表中添加第二个ng-repeat
:
<table>
<tr ng-repeat="d in stuff">
<td ng-repeat="(key, value) in d">
{{value}}
</td>
</tr>
</table>
Its worth noting this will only be valid markup if all results in d are equal in length. 值得注意的是,这仅在d中所有结果的长度相等时才是有效标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.