小编mar*_*coB的帖子

在Angular上使用lodash过滤对象数组

我在Angular 7上工作,我想对从后端收到的对象列表应用几个过滤器。这些对象属于我称为“ CV”的类型。CV内部还有其他对象,如下所述。

CV {
  employee: Employee;
  certifications: Certification[];
}
Employee {
  empId: number;
  empAgency: string;
  empBu: string;
}
Run Code Online (Sandbox Code Playgroud)

我的主要问题是我需要根据嵌套对象的属性过滤CV列表。

通过本教程,我得到了很多启发,可以应用多个过滤器:https : //angularfirebase.com/lessons/multi-property-data-filtering-with-firebase-and-angular-4/

我在typeScript中尝试过类似的方法。

  employees: CV[];
  filteredEmployees: CV[];
  //array I use to filter
  filters = {};
  
  //properties I wanna filter by
  empAgency: string;
  empBu: string;
  //standard entry to delete a filter property value
  private DefaultChoice: string = "DefaultChoice";
  
   private applyFilters() {
    if (this.filteredEmployees.length === this.employees.length) {
      this.filteredEmployees = _.filter(this.filteredEmployees,     _.conforms(this.filters));
    } else {
      this.filteredEmployees = this.employees;
      this.filteredEmployees = …
Run Code Online (Sandbox Code Playgroud)

nested filter lodash angular

5
推荐指数
1
解决办法
226
查看次数

标签 统计

angular ×1

filter ×1

lodash ×1

nested ×1