我可以通过以下步骤来完成这项工作:
ajax.get('/first-url')
.map(res => new Thing(res.response)
.mergeMap(firstThing=>
ajax.get(`/second-url?code=${firstThing.code}`)
.map(res => new OtherThing(res.response))
.map(secondThing => [firstThing, secondThing])
).map(([firstThing, secondThing]) => console.log(firstThing, secondThing))
从本质上讲,在第二个可观测数据的响应中,返回我想要在外部可观测数据中使用的确切数组
.map
这似乎是RXJS处理这一问题的理想方式。在RXJS的5.x版本中,有一个叫做结果选择器的东西,它可以作为第二个参数传入以创建类似的东西(它看起来很像最后一个内部
地图
)但对于RXJS V6.0,这似乎已被弃用:
https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#howto-result-selector-migration