【问题标题】:mat-select - mat-option sort valuesmat-select - mat-option 排序值
【发布时间】:2019-01-28 01:26:14
【问题描述】:

我是 Angular6 的新手,我想知道是否有一种简单的方法可以做我想做的事。

我刚刚阅读了文档,但没有阅读任何相关内容,有没有一种简单的方法可以对下拉列表中的值进行排序?

<mat-form-field>
      <mat-select placeholder="Code List" required [(ngModel)]="contextScheme.codeListId">
        <mat-option *ngFor="let codeList of codeLists" [value]="codeList.codeListId">
            {{codeList.codeListName}}
        </mat-option>
      </mat-select>
</mat-form-field>

基本上我拥有的值是我的数据库中按 id 排序的值,我想要确切的东西,但按 desc 排序。

提前致谢。

红袜队-。

【问题讨论】:

    标签: html angular typescript angular6


    【解决方案1】:

    您应该在数据库后端进行排序,或者按照 Angular 团队在no order-by pipe 中的建议,它应该在组件内部完成。 例如。如果你的组件中有一个数组,你可以使用Array.sort

    【讨论】:

    • 没有任何 typescript 方法来反转数组吗?谢谢你的回答!
    • @Sox, yourArray.reverse() docs
    猜你喜欢
    • 1970-01-01
    • 2019-02-07
    • 2023-03-21
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多