如何使用AngularJS显示此JSON格式

时间:2014-11-10 00:16:56

标签: json angularjs

我有两种JSON格式,

JSON -

[
    { 
        "name":"Alex", 
        "country":"United States"
    }, 
    { 
        "name":"Jaswanth", 
        "country":"India"
    }
]

AngularJS代码 -

我能够显示输出

<div ng-repeat="result in results">             
    {{result.name}} - {{result.country}}
</div>

但如果我改变了我的JSON,我就无法看到输出..

[
    {
        "info": [
            "one",
            "two",
            {
                "id": 944589,
                "contractYear": 2014
            }
        ],
        "country": "India",
        "name": "jaswanth"
    },
    {
        "info": [
            "three",
            "four",
            {
                "id": 944589,
                "contractYear": 2014
            }
        ],
        "country": "US",
        "name": "jass"
    }
]

如何更改AngularJS代码?

1 个答案:

答案 0 :(得分:1)

<div ng-init="init();">
    <div ng-repeat="result in data">             
        {{result.name}} - {{result.country}}
        <br/>
        <div ng-repeat="(k,v) in result.info">
            <span ng-if="v.id">The id is: {{v.id}}</span>
            <span ng-if="(!v.id)">{{v}}</span>
        </div>
        <hr/>
    </div>
</div>