NG-重复(迭代)在以上复杂的角json对象 [英] ng-repeat (iterate) over complex json object in Angular

查看:165
本文介绍了NG-重复(迭代)在以上复杂的角json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个控制器返回我一个非常复杂的JSON对象:

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> 

本code,我得到的一部分,如果该对象印在HTML响应:

with this code I get part if the object printed on the html response:

{"1443564000000":{"num":1}}

但是,正如你所看到的,会是个非常复杂的属性(我用的会话ID来存储它的数目)

But as you can see, sessions has a very complex attribute (I use the id of the session to store the number of it)

我看到有些人用来做与NG-重复启动,使用我的情况下,它给了我severals错误。

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

推荐答案

假设你想在会遍历属性,它是不是一个数组而是一个对象,你将不得不遍历对象的属性:

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:

&LT; TR NG重复=(键,值)数据&GT;

下面是一个例子: http://plnkr.co/edit/7AQF6k7hf2aZbWFmhVoX? p = preVIEW

有关问题的SO所在的例子是:<一href=\"http://stackoverflow.com/questions/15127834/how-can-i-iterate-over-the-keys-value-in-ng-repeat-in-angular\">How我可以遍历键,在角 NG-重复值

relevant SO questions where the example is from: How can I iterate over the keys, value in ng-repeat in angular

这篇关于NG-重复(迭代)在以上复杂的角json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆