简体   繁体   中英

Angular group comma separated values in select options

i'm having this problem i can't group this comma separated values in select dropdown options, here is my code:

here is the model:

在此处输入图片说明

Angular code:

<select ng-model="attrModel" ng-options="option.Value group by option.Key.Name for option in attrModel track by option.Value"></select>

Result:

在此处输入图片说明

Expceted Result:

在此处输入图片说明

The problem is that you pass the whole Value array as the value to the <option> tag.

I am not 100% sure how to handle nested arrays within a select properly but you can use <optgroup> for it.

<select ng-model="myFixedSelection">
  <optgroup ng-repeat="group in attrModel track by $index" label="{{group.Key.Name}}">
    <option ng-repeat="value in group.Value track by $index" >{{ value }}</option>
  </optgroup>
</select>

See the working plnkr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM