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

"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"}}发布于 2015-09-25 19:13:00
您应该纠正json结构&在响应中不应该包含"0“、"1”和"2“,您只需使用一个数组就可以解决问题。
更新的JSON
{
"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提出了一个很好的选择,如果你不能控制数据&不想改变它。那么您应该使用以下选项
<select>
<option ng-repeat="(key, value) in handoff">Document Type : {{value.documentType}}</option>
</select>https://stackoverflow.com/questions/32788114
复制相似问题