gpt4 book ai didi

javascript - Angular 2. 如何申请orderBy?

转载 作者:数据小太阳 更新时间:2023-10-29 03:58:52 24 4
gpt4 key购买 nike

我有一段代码。

<table class="table table-bordered table-condensed" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<tr *ngFor="#participant of participants; #i = index">
<td>{{i+1}}</td>
<td>{{participant.username}}</td>
<td>{{participant.score}}</td>
</tr>
</tbody>
</table>

在 Angular 1 中,我有 orderBy 过滤器来按我的过滤器对行进行排序。但是我怎样才能以同样的方式在 Angular 2 中执行 orderBy 呢?谢谢。

最佳答案

如果你正在使用 lodash 你的管道可以是这样的:

import { Pipe, PipeTransform } from '@angular/core';
import { orderBy } from 'lodash';

@Pipe({
name: 'orderBy'
})
export class OrderByPipe implements PipeTransform {
transform = orderBy;
}

然后您可以使用该方法的所有功能:

<li *ngFor="let product of products | orderBy: 'price': 'desc'">
{{product.name}}
</li>

关于javascript - Angular 2. 如何申请orderBy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35461203/

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