[英]ng-repeat (iterate) over complex json object in Angular
One controller returns me a very complex json object: 一个控制器向我返回了一个非常复杂的json对象:
{
"184": {
"title": "THE STONE ROSES",
"sessions": {
"1443564000000": {
"num": 5
},
"1442959200000": {
"num": 1
},
"1447196400000": {
"num": 1
},
"1444428000000": {
"num": 2
},
"1446332400000": {
"num": 3
}
}
}
} }
I have tried to iterate over it on my view like this 我试图像这样在我的视图上进行迭代
<div class="large-6 columns" ng-repeat="item in showItems" st-raw>
<h1>{{item.sessions}}</h1>
</div>
with this code I get part if the object printed on the html response: 使用此代码,如果对象打印在html响应上,我会得到帮助:
{"1443564000000":{"num":1}}
But as you can see, sessions has a very complex attribute (I use the id of the session to store the number of it) 但是如您所见,会话具有非常复杂的属性(我使用会话的ID来存储会话的数量)
I have seen that some people used to do that with ng-repeat-start, on my case using it gives me severals errors.. 我已经看到有些人以前用ng-repeat-start来做,在我的情况下使用它会给我带来几个错误。
Assuming that you want to iterate over the sessions
property, which is not an array but an object, you would have to iterate over the object's properties: 假设您要遍历sessions
属性,该属性不是数组而是对象,则必须遍历该对象的属性:
<tr ng-repeat="(key, value) in data">
Here is an example: http://plnkr.co/edit/7AQF6k7hf2aZbWFmhVoX?p=preview 这是一个示例: http : //plnkr.co/edit/7AQF6k7hf2aZbWFmhVoX?p=preview
relevant SO questions where the example is from: How can I iterate over the keys, value in ng-repeat in angular 相关的SO问题,该示例来自哪里: 如何迭代键,ng-repeat中的值以angular为单位
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.