简体   繁体   English

在结果中加入一些带有名称可观察函数的可观察对象?

[英]forkJoin some observables with name observable function in result?

Lets suppose there is array of Observable function: 让我们假设有一个Observable函数数组:

A(): Observable<any>
B(): Observable<any>

Then using forkJoin I await response from both Observables: 然后使用forkJoin等待两个Observable的响应:

let g = forkJoin([A(), B()]);

After subscription on g I can get results from both Observables. 订阅g之后,我可以从两个Observables获得结果。

Due this question, how to know from which Observable I have got result, I mean A(), or B(). 由于这个问题,如何知道我从哪个Observable得到了结果,我的意思是A()或B()。

Is it possible to get names or reference to these functions? 是否可以获取名称或引用这些功能?

More detailed explanation: 更详细的解释:

I have unknown number of Observable functions. 我没有数量可观察的函数。 I need to wait them executions, to get response then enable button. 我需要等待他们执行,以获得响应,然后启用按钮。 So, also I need to handle response in each of them body, or in common body response in forkJoin 因此,我还需要处理每个主体的响应,或者在forkJoin中处理公共主体的响应

The new observable will resolve an array of results, which are in the same order as that specified in the forkJoin 新的observable将解析结果数组,其顺序与forkJoin中指定的顺序相同

g.subscribe([a, b] => {
  console.log(a);
  console.log(b);
})

See Example 5 from the docs 请参阅文档中的示例5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM