ng-repeat (iterate) over complex json object in An

2019-09-02 17:44发布

One controller returns me a very complex json object:

{
"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:

{"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)

I have seen that some people used to do that with ng-repeat-start, on my case using it gives me severals errors..

1条回答
孤傲高冷的网名
2楼-- · 2019-09-02 17:49

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:

<tr ng-repeat="(key, value) in data">

Here is an example: 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

查看更多
登录 后发表回答