使用angularjs显示复杂JSON中的下拉值
我是新手。 我从一个web服务调用中获得以下JSONArray。要求显示子数组选项和文本中的值。我的下拉列表应显示为从以下HTML生成的内容:使用angularjs显示复杂JSON中的下拉值,json,angularjs,Json,Angularjs,我是新手。 我从一个web服务调用中获得以下JSONArray。要求显示子数组选项和文本中的值。我的下拉列表应显示为从以下HTML生成的内容: <select> <option value="L1" > English </option> <option value="L2" > French </option> <option value="L3" > Chainese </option> </se
<select>
<option value="L1" > English </option>
<option value="L2" > French </option>
<option value="L3" > Chainese </option>
</select>
请建议解决方案。您有奇怪的JSON格式: 以下是使用完整解决方案的工作标记和plnker:
如果我们有多个文本数组fieldsoption.text[0]。标签是他们的首选访问标签的方式吗?不确定您的问题是什么。。。在您提供的json中,有一个数组字段文本,但您只提供了一个元素。因此,我将其绑定到该数组的第一个[0]元素。。。如果只有一个数组元素,可以将结构展平,并将代码/顺序/语言/标签保留在一个级别。或者,您可以向该数组中添加其他项,并仅通过索引进行访问,例如[1]。
<td data-ng-repeat="field in json">
<select tabindex="0" data-ng-options="option.code as option.code as option.text.label for option in field.options" data-ng-model="language_code">
<option value=""> Select...</option>
</select>
[{
"id": null,
"code": "Language",
"order": 1,
"options": [
{
"code": "L1",
"order": 1,
"text": [
{
"language": "eng",
"label": "English",
}
]
},
{
"code": "L2",
"order": 2,
"text": [
{
"language": "fre",
"label": "French",
}
]
},
{
"code": "L3",
"order": 3,
"text": [
{
"language": "chn",
"label": "Chainese",
}
]
}
]
}]
<table>
<tr>
<td ng-repeat="field in json">
<select tabindex="0" ng-model="selected" data-ng-options="option.code as option.text[0].label for option in field.options">
<option value=""> Select...</option>
</select>
{{selected}}
</td>
</tr>
</table>