0
我試圖合併2個可觀測物。第一個可觀察到的持有ShoppingCart
類,第二個持有ShoppingItems
列表。我想將觀察點與購物車項目(Observable<ShoppingItems
)映射到名爲shoppingList$
的ShoppingCart
類中的實例變量。將2個可觀察物合併/合併成一個
可觀察到1:Observable<ShoppingCart>
這裏的購物車類的一個片段。
可觀察2:Observable<ShoppingItems[]>
私人觀察到的:可觀察
這裏是我使用的功能。
retrieveShoppingCartComplete(shoppingCartId: string): Observable<ShoppingCart> {
/**Returns the requested shopping cart, with the Ids of the shopping items in an array called shoppingCart.ShoppingItems*/
let shoppingCart$ = this.retrieveShoppingCart_AsEntity(shoppingCartId);
/** returns an Observable<ShoppingItems[]> of the requested ShoppingItems as entitys*/
let shoppingItems$ = shoppingCart$.map(shoppingCart => this.leS.retrieveShoppingItemsComplete(shoppingCart.ShoppingItemsIds))
return shoppingCart$.combineAll(shoppingItems$);
}
但是上述方法返回一個Observable<[ShoppingCart | ShoppingItems[]]>
不與ShoppingCart
類