如何将变量传递给RxJS subscribe()?

时间:2017-09-07 09:25:02

标签: javascript rxjs

我有以下代码:

upload(file) {
  let uploadData = new UploadData();
  this.active_uploads.push(uploadData);
  this.server.get_presigned_post_url().subscribe(url => {
    uploadData.id = extractIdFromUrl(url);
    this.uploader.uploadFile(file, url, () => {
      //success callback
      console.log(uploadData.id + ' done');
    }); 
  });
}

问题在于,如果我快速连续多次调用upload(),

uploadData.id = ...

和/或

console.log(uploadData.id + ' done'); 

似乎从另一个upload()调用中引用了错误的uploadData实例。

为什么? 处理它的正确方法是什么? 我可以将变量传递给订阅呼叫吗?

0 个答案:

没有答案