Rxjs - How can I extract multiple values inside an array and feed them back to the observable stream synchronously

后端 未结 3 1377
青春惊慌失措
青春惊慌失措 2020-12-16 06:01

I have created a Rx.Observable from a stream of events:

Rx.Observable.fromEvent(recognizeStream, \'data\')

In which every data

3条回答
  •  攒了一身酷
    2020-12-16 06:27

    You should pluck "alternatives" then to iterate over the array use from, as from creates a new observable you need to flatten up it, so use you need flatMap to do the job. So finally you have alternatives back into the stream.

    try it:

    var data = {
      error: null,
      alternatives: [{
        result: 1
      }, {
        result: 2
      }, {
        result: 3
      }]
    }
    
    var input$ = Rx.Observable.of(data);
    input$.pluck('alternatives').flatMap(alternatives => Rx.Observable.from(alternatives)).subscribe(alternative => console.log(alternative));

提交回复
热议问题