首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >我如何重构这个RXJS / Angular代码?

我如何重构这个RXJS / Angular代码?
EN

Stack Overflow用户
提问于 2018-06-02 07:33:50
回答 1查看 75关注 0票数 1

如何重构这些嵌套数组,以便在所有订阅完成后可以调用某些内容?我确信它与管道、mergeMaps、concatMaps等的组合有关。

代码语言:javascript
复制
this.teams = [
{
    Assignments: [{Id: 0, Name: 'assignment', Notes: 'notes'}]
},
{
    Assignments: [{Id: 0, Name: 'assignment', Notes: 'notes'}]
}]
    this.teams.map((team:any) => {
        team.Assignments.map((a: Assignment) => {
          return this.videoService.getById(a.VideoId).subscribe(
            res => {
              let e = new Event();
              e.Id = a.Id;
              e.title = a.Name;
              e.location = '';
              e.message = a.Notes;
              e.startDate = a.StartDate;
              e.endDate = a.EndDate;
              e.video = res;
              e.team = team.Name;
              this.eventList.push(e);
            },
            err => {

          });
        })
      })
EN

回答 1

Stack Overflow用户

发布于 2018-06-02 08:44:30

使用lodash:

代码语言:javascript
复制
Observable.from(
    lodash.flatten(
        this.teams.map(team => team.Assignments)
        )
)
.flatMap(a => this.videoService.getById(a.VideoId))
. subscribe(
    res => {
        //handle individual responses
    },
    err => {},
    () => {
        //handle after all complete 
    }
)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50652138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档