美文网首页SAP
SAP Spartacus Title 下拉菜单列表数据的读取逻

SAP Spartacus Title 下拉菜单列表数据的读取逻

作者: _扫地僧_ | 来源:发表于2021-10-06 09:14 被阅读0次

    this.titleQuery 的赋值逻辑:

    class UserProfileService {
        constructor(userAccountService, authService, userProfileConnector, eventService, userIdService, query, command) {
            this.userAccountService = userAccountService;
            this.authService = authService;
            this.userProfileConnector = userProfileConnector;
            this.eventService = eventService;
            this.userIdService = userIdService;
            this.query = query;
            this.command = command;
            this.updateCommand = this.command.create((payload) => this.userIdService.takeUserId(true).pipe(switchMap((uid) => this.userProfileConnector.update(uid, payload.details).pipe(tap(() => {
                this.eventService.dispatch({ user: payload.details }, UserAccountChangedEvent);
            })))), {
                strategy: CommandStrategy.Queue,
            });
            this.closeCommand = this.command.create(() => this.userIdService
                .takeUserId(true)
                .pipe(switchMap((uid) => this.userProfileConnector
                .remove(uid)
                .pipe(tap(() => this.authService.logout())))));
            this.titleQuery = this.query.create(() => this.userProfileConnector.getTitles(), {
                reloadOn: [LanguageSetEvent],
            });
        }
        get() {
            return this.userAccountService.get();
        }
    

    类型是 Query,数据类型是 Title[]:

    万变不离其宗,还是通过 connector 去取数据:


    创建 query 实例时,要传入一个箭头函数作为 Loaderfactory:


    在执行 query create 方法时,通过 switchMapTo,触发这个 loaderFactory 的执行:


    最后通过传统的 HTTP client 去读取数据:


    更多Jerry的原创文章,尽在:"汪子熙":


    相关文章

      网友评论

        本文标题:SAP Spartacus Title 下拉菜单列表数据的读取逻

        本文链接:https://www.haomeiwen.com/subject/ebzkiltx.html