首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >一个JSON阵列的角圈

一个JSON阵列的角圈
EN

Stack Overflow用户
提问于 2015-09-25 18:04:29
回答 1查看 54关注 0票数 0

我现在有一个使用循环打印到屏幕上的JSON数组。目前,我可以在没有循环的情况下获得我想要的结果,但是当我试图将它转换成一个循环时,我会遇到一些问题。任何洞察力都会有帮助。谢谢。

这是我目前的代码:

代码语言:javascript
复制
<div>
    <h2>Document Type</h2>
    <select>
        <option>Document Type : {{handoff[0].documentType}}</option>
        <option>Document Type : {{handoff[1].documentType}}</option>
        <option>Document Type : {{handoff[2].documentType}}</option>
        <option>Document Type : {{handoff[3].documentType}}</option>
        <option>Document Type : {{handoff[4].documentType}}</option>
    </select>
    <select>
        <option ng-repeat="temp in handoff">Document Type : {{temp[0].documentType}}</option>
    </select>
    <select>
        <option ng-repeat="temp in handoff">Document Type : {{temp.documentType}}</option>
    </select>
</div>

我对第一个“选择”的结果是正确的,但是对于第二个和第三个没有结果。

以下是obj的样子:

代码语言:javascript
复制
"handoffs":{"0":{   "documentType":"0","conlID":"1230","userName":"CU0","handoff":"h=81878E9E772BCA176D868CA633BFB47D38274B1B209FD80856E56B47"
},"1":{"documentType":"1","conlID":"C010","userName":"A010","handoff":"ERROR: A temporary problem was encountered.  Please try your request again in a few minutes."},"3":{"documentType":"3","conlID":"C010","userName":"C10","handoff":"HANDOFF=81878E9E77FB56E56B47"}}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-25 19:13:00

您应该纠正json结构&在响应中不应该包含"0“、"1”和"2“,您只需使用一个数组就可以解决问题。

更新的JSON

代码语言:javascript
复制
{
    "handoffs": [{
            "documentType": "0",
            "conlID": "1230",
            "userName": "CU0",
            "handoff": "h=81878E9E772BCA176D868CA633BFB47D38274B1B209FD80856E56B47"
        },{
            "documentType": "1",
            "conlID": "C010",
            "userName": "A010",
            "handoff": "ERROR: A temporary problem was encountered.  Please try your request again in a few minutes."
        },{
            "documentType": "3",
            "conlID": "C010",
            "userName": "C10",
            "handoff": "HANDOFF=81878E9E77FB56E56B47"
        }]
    }
}

更新

@o4ohel提出了一个很好的选择,如果你不能控制数据&不想改变它。那么您应该使用以下选项

代码语言:javascript
复制
<select>
    <option ng-repeat="(key, value) in handoff">Document Type : {{value.documentType}}</option>
</select>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32788114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档