[英]Can I customize select to show the selected value different than what I've selected
I need to show hierarchy in the usual select control. 我需要在通常的选择控件中显示层次结构。 I implemented this by using \ inside of the option labels.
我通过在选项标签内使用\\ u00A0来实现此目的。
The hierarchy looks like this: 层次结构如下所示:
Audi
- A1
- A2
- A3
- A4
Ford
- Galaxy
- Mondeo
- Focus
But when the value selected I need to show the whole value (for ex. "Audi - A4"). 但是,当选择值时,我需要显示整个值(例如“ Audi-A4”)。 And if I expand the select again I still need to see the initial options list with "- A4" selected.
而且,如果再次展开选择,我仍然需要查看初始选项列表并选择“-A4”。 Js/angular solution is fine here.
JS /角解决方案在这里很好。 Please, advice.
请指教。
The best way to get this hierarchy is to use the grouping in ng-options directive, see plunker . 获取此层次结构的最佳方法是使用ng-options指令中的分组,请参见plunker 。
$scope.values = [
{ id: 1, make: 'Audi', type: 'A1' },
{ id: 2, make: 'Audi', type: 'A2' },
{ id: 3, make: 'Audi',type: 'A3' },
{ id: 4, make: 'Audi', type: 'A4' },
{ id: 5, make: 'Ford', type: 'Galaxy' },
{ id: 6, make: 'Ford', type: 'Mondeo' },
{ id: 7, make: 'Ford', type: 'Focus' }
];
$scope.selectedId = 1;
and then 接着
<select ng-options="item.id as item.make + ' ' + item.type group by item.make for item in values" ng-model="selectedId"></select>
This has the full name of the car in the select, groups by the make, but still, the individual options have the full name of the car. 该名称在选择中具有汽车的全名,按制造商分组,但是单个选项仍然具有汽车的全名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.