【发布时间】:2018-03-08 00:53:47
【问题描述】:
在我们的应用程序中解决(订阅)时,对于每个可观察到的,我都会在下面得到两个响应 -
obs1$.subscribe(x=>{
Response1 = x;
});
obs2$.subscribe(y=>{
Response2 = y;
});
Response1 = [{id: 1, qty: 0, description: "product1"},
{id: 2, qty: 0, description: "product2"},
{id: 3, qty: 0, description: "product3"}]
Response2 = [{id: 1, qty: 23, description: "product1"},
{id: 3, qty: 10, description: "product3"}]
我正在使用 RxJS Observables 并且对它相当陌生。我需要合并两个响应并根据两个响应的共同 id 更新数量(值应仅来自 Response2)。最终响应应如下所示 -
FinalResponse = [{id: 1, qty: 23, description: "product1"},
{id: 2, qty: 0, description: "product2"},
{id: 3, qty: 10, description: "product3"}]
如何使用 RxJS Observables 做到这一点?
【问题讨论】: