如何只显示得分最低的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

您可以在此我创建了一个管道来过滤数据...

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.