我只想显示 DL 列表中的 1 条记录,该记录具有所有 DL 中的最低分数。目前它正在显示所有记录。
在 stackblitz 的示例中,您可以看到第一条记录的 DL 分数为:54、20 并已更新。
我不想显示所有 3 条记录,而是只想显示 1 条得分最低的记录,即 20。
请建议。
Markup
<ul>
<li *ngFor="let assignee of user.assigned_to">
{{assignee.dl}} {{assignee.co_score}}
</li>
</ul>
Live
https://stackblitz.com/edit/angular-ivy-1tsz1r?file=src%2Fapp%2Fapp.component.html https://stackblitz.com/edit/angular-ivy-1tsz1r?file=src%2Fapp%2Fapp.component.html
您可以在此处找到工作示例堆栈闪电战链接 https://stackblitz.com/edit/angular-ivy-7nnnby?file=src%2Fapp%2Ffilter-dl.pipe.ts
我创建了一个管道来过滤数据......
自定义管道是
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "filterDL"
})
export class FilterDLPipe implements PipeTransform {
transform(value: any, args?: any): any {
console.log("filter pipe ", value);
let filter = value.filter(item => Number(item.co_score));
let leastScrore = Math.min(...filter.map(item => item.co_score));
let findIndex = filter.filter(item => item.co_score === leastScrore);
console.log("findex", findIndex);
console.log(leastScrore);
return findIndex;
}
}
然后将此管道应用于您的 DL 数组以过滤掉数组。
<ul>
<li *ngFor="let assignee of user.assigned_to | filterDL">
{{assignee.dl}} {{assignee.co_score}}
</li>
</ul>
您将在 DL 中获得所需的最低分数输出。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)