有什么方法可以过滤 {} 而不放置额外的地图吗?
Are there any way to filter of{} not put aditional map?
我有管道,当出现错误时它会 return of{}
。所以我需要过滤它,到其他代码流。目前我使用以下 senario。我需要知道,有什么方法可以删除地图并在现有过滤器中对其进行过滤吗?
readonly k$ = combineLatest(
[this.x$.pipe(filter(isNotNullOrUndefined), //this filter not filtering of{} type.
map((res: A) => { //need to remove this map
return res;
})
), this.y$]).pipe(shareReplayUntil(this.destroySub));
你是说一个空对象的可观察对象of({})
?
您可以使用 Object.keys(res).length !== 0
检查它是否不为空
filter((res: A) => isNotNullOrUndefined(res) && Object.keys(res).length !== 0)
您可以 return of(null)
而不是 of({})
以便您的过滤器函数 isNotNullOrUndefined
正确过滤 null
值。
我有管道,当出现错误时它会 return of{}
。所以我需要过滤它,到其他代码流。目前我使用以下 senario。我需要知道,有什么方法可以删除地图并在现有过滤器中对其进行过滤吗?
readonly k$ = combineLatest(
[this.x$.pipe(filter(isNotNullOrUndefined), //this filter not filtering of{} type.
map((res: A) => { //need to remove this map
return res;
})
), this.y$]).pipe(shareReplayUntil(this.destroySub));
你是说一个空对象的可观察对象of({})
?
您可以使用 Object.keys(res).length !== 0
filter((res: A) => isNotNullOrUndefined(res) && Object.keys(res).length !== 0)
您可以 return of(null)
而不是 of({})
以便您的过滤器函数 isNotNullOrUndefined
正确过滤 null
值。