有两种型号。
模型1:
export class Project{
constructor(
public project_id?:number,
public name?: string,
public comments?: string,
public version?: string,
public date?: Date
) { }
}
模特2:
export class Test{
constructor(
public test_id?:number,
public projects_id?: number,
public name?: string,
public date?: Date,
public is_check?: string
) { }
}
如何通过id projects_id
过滤它们来显示“测试”模型中的数据。也就是说,有必要根据“项目”中的数据过滤“测试”模型中的数据。这是在没有过滤器的情况下加载数据的功能:
tests: Array<Test>;
projects: Array<Project>;
ngOnInit() {
this.getTests();
}
getTests() {
this.servTest.getTests().subscribe(
tests => this.tests = tests
);
}
您可以使用Array.filter,如下所示,
this.servTest.getTests().subscribe(
tests => this.tests = tests.filter(t=>t.projects_id === yourProjectId);
);