【发布时间】:2020-04-22 03:27:43
【问题描述】:
这是我想要完成的一个非常简单的版本。目前它正在按预期工作,但我只是想知道是否有更短/更清洁的方法来实现 pipe() 内部的运算符
当前行为: 在包含数组“项目”的属性的可观察对象上调用管道。 在管道内部,过滤、排序然后将项目发布到行为主体。
public items$: BehaviorSubject
public testObservable = () =>
of({
Test: '123',
Properties: 'props',
Items: [
{ key: 1, val: 'test1' },
{ key: 2, val: 'test2' },
{ key: 3, val: 'test3' }
]
});
testMethod() {
this.testObservable()
.pipe(
pluck('Items'),
map(items => items.filter(item => item.key != 2)),
map(items => items.sort((a, b) => (a.key > b.key ? 1 : -1))),
tap(items => { this.items$.next(items) })
);
【问题讨论】:
标签: angular typescript rxjs