日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SAP Spartacus CurrentProductService返回的null对象

發布時間:2023/12/19 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SAP Spartacus CurrentProductService返回的null对象 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用如下的代碼監控getProduct可能返回的null值:

import { Component, OnInit } from '@angular/core'; import { ActiveCartService, Product } from '@spartacus/core'; import { CurrentProductService } from '@spartacus/storefront'; import { Observable, OperatorFunction } from 'rxjs'; import { filter, map } from 'rxjs/operators';@Component({selector: 'app-mycom',templateUrl: './mycom.component.html',styleUrls: ['./mycom.component.scss'] }) export class MycomComponent implements OnInit {jerryfilter: OperatorFunction<Product, Product> =filter(this.jerrytest2);product$: Observable<Product> = this.currentProductService.getProduct().pipe(this.jerryfilter);productName$ = this.product$.pipe(map(product => product.name));jerrytest2(product: Product): boolean {const result = !!product;if (result === false) {console.log('false!');}return result;}constructor(private currentProductService: CurrentProductService, private cartService: ActiveCartService) {}ngOnInit(): void {this.product$.subscribe(product => console.log(product));}}

TypeScript語句jerryfilter: OperatorFunction<Product, Product> =
filter(this.jerrytest2);

對應的JavaScript函數:

jerryfilter的JavaScript實現是一個名字叫filter的function,接收一個predicate function作為輸入參數,返回一個新的函數,總金額和新的函數會基于傳進來的predicate新建一個filterOperator實例:

export function filter(predicate, thisArg) {return function filterOperatorFunction(source) {return source.lift(new FilterOperator(predicate, thisArg));};

product$: Observable = this.currentProductService.getProduct().pipe(this.jerryfilter);

注意,product$是一個Observable對象,不是實際的product值:

operator指向了我傳入的filter.

product$也是Observable,因此可以繼續調用pipe.

返回為false的情況:

filter的實現,如果箭頭函數返回false,就不往下繼續執行了:

要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":

總結

以上是生活随笔為你收集整理的SAP Spartacus CurrentProductService返回的null对象的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。