【发布时间】:2019-03-26 04:23:27
【问题描述】:
getBudgetMap(budgetMonthID){
this.rows = [];
this.categoryService.getCategory(budgetMonthID).subscribe(category =>{
this.categoryList = category;
this.categoryList.forEach(category => {
this.transactionService.getTransaction(budgetMonthID, category.id).subscribe(transaction => {
this.rows = this.rows.concat(transaction);
})
})
)
}
为了简单起见,我有一个嵌套的 ajax 服务 (http.get) 调用,第一个调用 (getCategory) 返回基于 budgetMonthID 的类别列表。类别的数量各不相同。然后每个类别将进行第二次调用getTransaction 以检索属于每个类别的所有事务。上面的代码运行良好,但我一直在阅读关于 Angular 的map、flapMap、pipe,我只是不知道如何更改那个讨厌的代码。谢谢
【问题讨论】:
-
您使用的是哪个 DBMS?
-
我相信你会得到很好的答案,但我认为你现在拥有的这段代码远非“讨厌”(除了巨大的缩进 :)),而且可能更容易不惜一切代价阅读/维护而不是使用 RxJS 运算符。只是我的 2 美分。
标签: angular dictionary pipe subscribe flatmap