编辑API函数以按所有选定的过滤器进行过滤,而不是仅过滤最近的过滤器

时间:2017-05-04 21:13:44

标签: javascript angular mongoose eventemitter

我已经构建了一个函数来处理基于一系列复选框过滤器的过滤数据,用户可以在我的Angular应用程序中点击这些过滤器。现在我已经完成了这个功能,只要选择了四个过滤器中的一个,数据就会根据该选择进行过滤。但是,当用户单击下一个过滤器时,当数据过滤以匹配此请求时,它会丢失先前的过滤器。

换句话说,它只根据最近的过滤器选择进行过滤。如何编辑此功能以便过滤所有当前选定的过滤器?这是我目前的功能:

onFilterReceived(value, type) {
    if (type === 'lan' && value) {
        this.streamFiltersService.getByFilter(this.page, this.pagesize, {
            "services.workflow.status" : "visiting",
            "languages.primary" : { $in: value }
            })
            .subscribe(resRecordsData => {
                this.records = resRecordsData;
                console.log('Visiting onLanguageReceived language: ' + value + ' type: ' + type);
            },
            responseRecordsError => this.errorMsg = responseRecordsError);
    } else if (type === 'dis' && value) {
        this.streamFiltersService.getByFilter(this.page, this.pagesize, {
            "services.workflow.status" : "visiting",
            "services.service" : { $in: value }
            })
            .subscribe(resRecordsData => {
                this.records = resRecordsData;
                console.log('Visiting onDisciplineReceived discipline ' + value + ' type: ' + type);
            },
            responseRecordsError => this.errorMsg = responseRecordsError);
    } else if (type === 'zip' && value) {
        this.streamFiltersService.getByFilter(this.page, this.pagesize, {
            "services.workflow.status" : "visiting",
            "addresses.postalCode" : { $in: value },
            })
            .subscribe(resRecordsData => {
                this.records = resRecordsData;
                console.log('Visiting onZipcodeReceived: ' + value + ' type: ' + type);
            },
            responseRecordsError => this.errorMsg = responseRecordsError);
    } else if (type === 'branch' && value) {
        this.streamFiltersService.getByFilter(this.page, this.pagesize, {
            "services.workflow.status" : "visiting",
            "branch" : { $in: value }
            })
            .subscribe(resRecordsData => {
                this.records = resRecordsData;
                console.log('Visiting Branch ' + value + ', type: ' + type);
            },
            responseRecordsError => this.errorMsg = responseRecordsError);
     } else {
        this.streamFiltersService.getByFilter(this.page, this.pagesize, {
            "services.workflow.status" : "visiting"
        })
            .subscribe(resRecordsData => {
                this.records = resRecordsData;
            },
            responseRecordsError => this.errorMsg = responseRecordsError);
    }
}

我使用Angular的Output()和EventEmitter()将事件从一个组件发送到另一个组件。该模板视图如下所示:

        <list [records]="records" 
            (sendBranch)="onFilterReceived($event, type = 'branch')"
            (sendZipcode)="onFilterReceived($event, type = 'zip')"
            (sendLanguage)="onFilterReceived($event, type = 'lan')"
            (sendDiscipline)="onFilterReceived($event, type = 'dis')">
        </list>

0 个答案:

没有答案