本文介绍了如何只显示得分最低的1条记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想显示DL列表中只有1条记录,该记录在所有DL中得分最低.当前正在显示所有记录.

I wanted to show only 1 record among the DL list which has a minimum score from all the DLs. Currently it's displaying all the records.

在stackblitz的示例中,您可以看到第一条记录的DL得分是:54、20和已更新.

In the example on stackblitz you can see for the first record DL scores are : 54, 20 and updated.

我想要显示3条记录,而不是只显示得分最低的记录,即20分.

I want Instead of showing all 3 records I wanted to display only 1 record which has least score i.e. 20.

请提出建议.

标记

<ul>
<li *ngFor="let assignee of user.assigned_to">
{{assignee.dl}} {{assignee.co_score}}
</li>
</ul>

直播 https://stackblitz.com/edit/angular-ivy-1tsz1r?file = src%2Fapp%2Fapp.component.html

推荐答案

您可以在此 stackbliz链接

我创建了一个管道来过滤数据...

I have created one pipe to filter out data...

自定义管道是

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数组以过滤出数组.

then apply this pipe to your DL array to filter out array.

<ul>
     <li *ngFor="let assignee of user.assigned_to | filterDL">
                {{assignee.dl}} {{assignee.co_score}}
     </li>
</ul>

您将在DL中获得所需的最低分数.

and you will get your desired minimum score outpur in DL.

这篇关于如何只显示得分最低的1条记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 16:52