gpt4 book ai didi

html - 下拉列表的字母排序

转载 作者:搜寻专家 更新时间:2023-10-30 21:15:14 25 4
gpt4 key购买 nike

我刚开始使用 Angular 2 和 TypeScript。我很难为其实现代码。

我的问题是如何对下拉列表中的选项进行排序?

这是 HTML 代码:

<div class="col-12">
<select class="form-control" id="type" [(ngModel)]="measure" (change)="getMeasures()">
<option *ngFor="let option of options" [ngValue]="option.measure">{{option.display}}</option>
</select>
</div>

这是我的 TypeScript 选项部分:

    options = [
{
measure: 'length',
display: 'Length'
},
{
measure: 'area',
display: 'Area'
},
{
measure: 'volume',
display: 'volume'
},
{
measure: 'time',
display: 'Time'
},
{
measure: 'current',
display: 'Current'
},
{
measure: 'energy',
display: 'Energy'
},

]

最佳答案

已接受的答案不再有效。根据 https://angular.io/guide/pipes 处的文档

Appendix: No FilterPipe or OrderByPipe Angular doesn't provide pipes for filtering or sorting lists. Developers familiar with AngularJS know these as filter and orderBy. There are no equivalents in Angular.

This isn't an oversight. Angular doesn't offer such pipes because they perform poorly and prevent aggressive minification. ... While some may not care to minify this aggressively, the Angular product shouldn't prevent anyone from minifying aggressively. Therefore, the Angular team decided that everything Angular provides will minify safely.

The Angular team and many experienced Angular developers strongly recommend moving filtering and sorting logic into the component itself.

关于html - 下拉列表的字母排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44683459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com