0

我有两个从 firebase 获得的 observables。这两个 observable 有两个公共变量:一个是 bankAccountId,另一个是 linkTobankAccountId。我需要将这些 observable 合并到一个具有以下结构的对象中:

{
   {
       bankAccounts:
           {
               bankAccountId1
               ...bankFields
                   }, 
           {    
               bankAccountId2
               ...bankFields 
               }
},
   {    debitCards:
           {
               linkToBankAccountId1
               ...debitCardfields
               }
   }
}

我没有很多合并可观察对象的经验。我尝试了很多事情,但到目前为止我还没有成功。我在语法上有问题——特别是对我用作键的变量进行“内连接”。这是我的代码:

this.vm$ = combineLatest([
      this.caregiverBankAccounts$
    .pipe(switchMap(banks =>
          banks.bankAccountId)),
  this.caregiverDebitCards$.pipe(
    map(([debit, linkTobankAccountId]) => {
    linkTobankAccountId === bankAccountId;
}))
]);

我意识到语法是错误的。我收到一个错误,它找不到bankAccountId。我不知道如何使它工作。

4

1 回答 1

0

在下面的函数中,我正在映射 observables,然后将它们加入索引。

this.vm$ = combineLatest([
      this.caregiverBankAccounts$,
      this.caregiverDebitCards$,

    ])
      .pipe(map(([bank, debit]) => {
        const combinedStream = bank.map((item, i) => Object.assign({}, item, debit[i]));
        console.log(combinedStream);
        return [...combinedStream];


        }

       ));
于 2021-06-04T13:27:46.377 回答