我正在使用Angular 7,希望对从后端接收到的对象列表应用多个过滤器。 这些对象是我称之为"CV"类型的。 "CV"中包含其他对象,如下所述。
CV {
employee: Employee;
certifications: Certification[];
}
Employee {
empId: number;
empAgency: string;
empBu: string;
}
我的主要问题是,我需要根据嵌套对象的属性来过滤简历列表。
这篇教程启发了我,让我学会了如何应用多个过滤器: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 = _.filter(this.filteredEmployees, _.conforms(this.filters));
}
}
filterExact(property: string, property2: string, rule: any) {
if (rule ==='DefaultChoice') {
delete this.filters[property][property2];
this.filters[property] = [];
this.filters[property][property2] = null;
}
else {
this.filters[property] = [];
this.filters[property][property2] = val => val === rule;
}
this.applyFilters();
}
但是它不能处理嵌套属性。我的问题是我不知道如何正确传递嵌套对象的属性到我的函数中。
有人可以帮忙吗?
通过帮助,我也包括任何关于如何在Angular中链式多个过滤器(使用/不使用lodash)的建议。我仍然是这个领域的新手,所以请随意指向好的方向!