繁体   English   中英

如何在 Angular 中对订阅的多个火灾进行故障排除

[英]How to troubleshoot multiple fires on subscription in Angular

我有一个使用一些过滤器的网格,这些过滤器显示在网格的左侧,每次用户对过滤器进行更改时,我们都会根据新选择重新加载数据。 这一切都按预期工作,但我遇到的问题是在初始负载时我们会开火两次,我无法为上帝和世界弄清楚为什么。 所以,我希望有人能给我一些关于为什么以及如何防止这种情况的想法。

这是我对过滤器更改的订阅

private listenForFilterChanges() {
    this.subs.push(
        this.filtersSidebarContainer
            .resources
            .pipe(
                debounceTime(500),
                distinctUntilChanged(),
            )
            .subscribe(filters => {
                this.onSideBarFilter(filters);
            })
    );
}

这是我正在调用的函数的代码

private onSideBarFilter(filters: IActiveFilter[]) {
    // Make sure grid has been initialized before trying to update the datasource
    if (this.agGridBase && this.agGridBase.api) {
        this.setActiveFilters(filters);

        // update data fetcher options
        filters.forEach(filter => {
            this.agGridBase.updateDataFetcherParam(<FarmsFilter>filter.group, filter.value.map(filterValue => filterValue.value));
        });

        this.setDataFetcherFactory();
        this.agGridBase.setDataSource('Side Bar Filter');
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM