我有一个从ajax调用返回的json对象:
0: Object
id: "0-0-0"
selected: "selected"
text: "option name"
value: 0
__proto__: Object
1: Object
id: "12-0-0"
selected: ""
text: "4C 1.75 16v Tbi ( TCT )"
value: 59885
我想填充像这样的选项的选项:
<option value="0" id="0-0-0" selected="selected">option name </option>
ng-options如何实现这一目标?
答案 0 :(得分:6)
ng-repeat
属性, id
更有意义:
<强> HTML:强>
<select>
<option ng-repeat="obj in results" id="{{obj.id}}" value="{{obj.value}}"
ng-selected="obj.selected === 'selected'">{{obj.text}}</option>
</select>
但是,如果它只是您所追求的数据(并且不需要为每个id
设置option
属性),ng-options
将会像这样工作:< / p>
<select ng-model="selection" ng-options="obj as obj.text for obj in results">
</select>