我需要使用 关联数组 作为select使用AngularJS的选项的数据源。
select
是否可以使用这样的数组?
{ "key1": "val1", "key2": "val2", "key3": "val3", ... }
并得到这样的东西:
<select> <option value="key1">val1</option> <option value="key2">val2</option> <option value="key3">val3</option> ... </select>
我阅读了docs,但是我不明白如何实现这一目标。
ng-option
<select ng-model="blah" ng-options="key as value for (key , value) in data"></select>
ng-repeat
<select> <option ng-repeat="(key, value) in data" value="{{key}}">{{value}}</option> </select>
$scope.data = { "key1": "val1", "key2": "val2", "key3": "val3", ... };