我怎样才能对 score 进行另一个过滤器来显示与范围匹配的结果?

How can I another filter for score which will show the results matching the range?

我想为分数添加另一个过滤器,选项有非常高、高、中等和低。如果分数 <20 然后低,21-50 然后中等,51-70 然后高,>71 然后非常高,它应该过滤匹配该范围的记录。

你能指导我在我的过滤器中需要更新什么吗? filter.pipe

import { Pipe, PipeTransform } from "@angular/core";

@Pipe({
  name: "tableFilter"
})
export class TableFilterPipe implements PipeTransform {
  transform(list: any[], filters: any) {
    const keys = Object.keys(filters).filter(key => filters[key]);
    const filterUser = (user: { [x: string]: any }) =>
      keys.every(key => {
        if (key == "sdob") {
          return (
            new Date(user["dob"]) >= new Date(new Date(filters[key]).setHours(0, 0, 0, 0))
          );
        } else if (key == "edob") {
          return (
            new Date(new Date(filters[key]).setHours(0, 0, 0, 0)) >= new Date(user["dob"])
          );
        } else if (key === "dl" && user["assigned_to"].filter((e: { dl: any; }) => e.dl === filters[key]).length) {
          return user;
        }
        else if (key == "score") {
          
        }
        else {
          return user[key] === filters[key];
        }
      });
    return keys.length ? list.filter(filterUser) : list;
  }
}

HTML/Template

<div class="form-group float-left mr-4">
          <strong>Score</strong>
          <br />
          <select class="form-control form-control-sm" name="score" ngModel [ngModelOptions]="{updateOn: 'submit'}">
            <option></option>
            <option value="">Low</option>
            <option value="">Medium</option>
            <option value="">High</option>
            <option value="">Very High</option>
          </select>
        </div>

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

请帮忙。

在您的代码中再添加一个 else if

else if (key === "score") {
      const low = filters[key] === "20" && user["score"] <= filters[key];
      const medium =
        filters[key] === "50" && user["score"] < 50 && user["score"] >= 21;
      const high =
        filters[key] === "70" && user["score"] < 70 && user["score"] >= 51;
      const veryHigh = filters[key] === "71" && user["score"] >= 71;
      if (low || medium || high || veryHigh) {
        return user;
      }
    } 

此外,发送来自 HTML 的值:

<option value="71">Very High</option>
      <option value="70">High</option>
      <option value="50">Medium</option>
      <option value="20">Low</option>

https://angular-ivy-xtgnv5.stackblitz.io 另外,如果您的问题得到解决,请标记为正确。