[英]How to pre-select default options in <select “multiple”> element using AngularJS
I have an object param that has these properties: 我有一个具有以下属性的对象参数 :
param.ValidValues (key-value array) param.ValidValues(键值数组)
param.DefaultValues (values string array) param.DefaultValues(值字符串数组)
I need to bind ng-model="param.DefaultValues" and make all default values to be pre-selected in that select listbox, so that when a user makes multiple selection, the selected values are added to param.DefaultValues array 我需要绑定ng-model =“ param.DefaultValues”并在该选择列表框中预先选择所有默认值,以便在用户进行多项选择时,将所选值添加到param.DefaultValues数组中
This code does the job well, please see the screenshot 此代码可以很好地完成工作,请参见屏幕截图
<select multiple ng-model="param.DefaultValues">
<option ng-repeat="item in param.ValidValues" value="{{item.Value}}" label="{{item.Key}}"></option>
</select>
However, the items, those values are in param.DefaultValues are not pre-selected by default . 但是,这些值都在param 中 。 默认情况下不会默认选择 DefaultValues。
How can I achive that? 我该如何实现? Thanks 谢谢
If I use ng-options instead, it also does not pre-select DefaultValues, and also doesnt add user selected values to DefaulValues array: 如果我改用ng-options,它也不会预先选择DefaultValues,也不会将用户选择的值添加到DefaulValues数组中:
<select ng-model="param.DefaultValues" ng-options="o.Value as o.Key for o in param.ValidValues" multiple>
<option value=""></option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.