[英]angular select bind dictionary
I try to bind the options of an to an dictionary: 我尝试将an的选项绑定到字典:
<select ng-model="vm.incident.State" ng-options="key for (key,value) in vm.stateOptionSet" style="width: 250px;">
as far everything works fine, but when I use this: 到目前为止一切正常,但是当我使用这个时:
<select ng-model="vm.incident.State" ng-options="key as value for (key,value) in vm.stateOptionSet" style="width: 250px;">
The Selectbox didn't select the entry which fits to the ng-model. 选择框未选择适合ng模型的条目。
Can someone tell me whats wrong? 有人可以告诉我怎么了吗?
Both of your examples are working. 您的两个示例都在工作。 Take a look to my example:
看一下我的例子:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="" ng-controller="customersController"> <select ng-model="selection" ng-options="key for (key,value) in optionSet" style="width: 250px;"></select> <select ng-model="selection" ng-options="key as value for (key,value) in optionSet" style="width: 250px;"></select> <br />Selection: {{selection}} </div> <script> function customersController($scope) { $scope.selection = {}; $scope.optionSet = { key1: "value1", key2: "value2" }; } </script>
Maybe you have forgotten that you have to close your select tag. 也许您忘记了必须关闭选择标签。
Using
select as
will bind the result of the select expression to the model , but the value of the<select>
and<option>
html elements will be either the index (for array data sources) or property name (for object data sources) of the value within the collection.使用
select as
将select表达式的结果绑定到模型 ,但是<select>
和<option>
html元素的值将是索引 (对于数组数据源) 或属性名称 (对于对象数据源)集合中的值。 If atrack by
expression is used, the result of that expression will be set as the value of the option and select elements.如果使用
track by
表达式track by
则该表达式的结果将设置为option和select元素的值 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.