使用管道和过滤器过滤数字[]的可观测值



我现在有一个非常奇怪的问题,我把它简化为最简单的代码。我想要实现的是过滤作为可观察的列表

import { of, Observable } from 'rxjs';
import { filter, map } from 'rxjs/operators';
const list = of([1, 2, 3]);
return list.pipe(
filter(x => x % 2 === 0)
);

我得到一个错误,x不是数字,而是数字[]

当然,在现实生活中,列表是从后端加载的,过滤功能要复杂得多。

rxjs 6.5.4打字脚本3.7.5

喝了一些额外的咖啡后:

const list = of([1, 2, 3]);
return list.pipe(
map(ll => ll.filter(x => x % 2 === 0))
);

最新更新