使用angularjs

时间:2015-09-03 04:26:17

标签: json angularjs

我是角度JS的新手。 我从Web服务调用获得以下JSONArray。要求是显示子数组“options”和“text”中的值。我的下拉列表应显示为从HTML下面生成:

<select>
 <option value="L1" > English </option>
 <option value="L2" > French </option>
 <option value="L3" > Chainese </option>
</select>

以下是我尝试使用角度ng选项的代码:

<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> 

我无法从基础对象访问“options”或“text”数组。

[{
    "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",
                }
            ]
        }
    ]
}]

请建议解决方案。

1 个答案:

答案 0 :(得分:0)

你有奇怪的JSON格式: 这里有工作标记和plnker完整的解决方案:http://plnkr.co/edit/OFyfJkTSgpoW2Gwkzzda

<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>