我正在使用switchMap
和mergeMap
,并且需要保留一些额外的数据。
查看代码
from(fileList)
.pipe(
mergeMap((file: File) => {
return this.s3Service.checkExists(file);
})
)
.subscribe((hash: any) => {
// I want to access to the `file:File` here as well
console.log(`hash exists`, hash, file);
});
如何实现?
答案 0 :(得分:1)
将s3Service.checkExists
方法的结果映射到包含原始文件的对象:
from(fileList)
.pipe(
mergeMap((file: File) => {
return this.s3Service.checkExists(file).pipe(map(hash => ({hash, file})));
})
)
.subscribe(data => {
// I want to access to the `file:File` here as well
console.log(`hash exists`, data.hash, data.file);
});