-1
我不是rxjs的专家。关于相同功能的开关图
我有一个方法,实际上保存。
this.saveProducts(this.boxes, 'BOXES')
但还有另外两种不同类型的项目需要使用相同的方法进行保存,只是参数不同而已。
this.saveProducts(this.containers, 'CONTAINER')
在我的组件中,我几乎没有其他的独立存储正在发生,所有这些都应该发生一个一个。
所以我的方法看起来像这样。
return this.service.edit(materials)
.do((data) => {
this.materials= data;
})
.switchMap(() => this.customerService.addCustomer(this.id, this.customers))
.switchMap(() => this.saveProducts(this.boxes, 'BOXES'))
.switchMap(() => this.saveProducts(this.containers, 'CONTAINER'))
.switchMap(() => this.saveProducts(this.books, 'BOOKS'))
.do(() => {
.......
}
但是发生了什么是它永远不会调用第二saveProducts方法,除非我从第一个返回
private saveProducts(products: IProduct[], type:
Type): Observable<any> {
console.log(type);
}