Combine multiple observable arrays into new object array

前端 未结 3 971
感情败类
感情败类 2021-01-14 01:44

I have 3 observable arrays like below.

persons = [
   {
      \"firstName\":\"john\",
      \"lastName\":\"public\",
      \"locationID\":\"1\",
      \"depa         


        
3条回答
  •  不思量自难忘°
    2021-01-14 02:32

    i think the RxJS .zip operator may be your friend here.

    As far as I understand, .zip emits like this ...

    .zip(
       Observable.from[array1].switchMap( // map to http response here ),
       Observable.from[array2].switchMap( // map to http response here ),
       Observable.from[array3].switchMap( // map to http response here )
    ).map((valueFromArray1, valueFromArray2, valueFromArray3) {
       // Create your object here 
    })
    

    Something like that! Hopefully, puts you on the right track.

    .zip should emit the first time when all 3 have emitted (and it will emit a second time when all three stream have emitted twice, etc) - In your scenario I expect all three stream emit once only, which makes it a simple case for .zip

提交回复
热议问题