【发布时间】:2019-09-02 19:52:03
【问题描述】:
使用ngrx,我从存储中获得了两个数据集。
private getCatalog() {
this.catalogStore.select(CatalogStoreSelectors.selectAllCatalogsLoadSuccess)
.pipe(
takeWhile(() => this.alive),
take(1),
filter(loadSuccess => !loadSuccess),
tap(() => this.catalogStore.dispatch(new CatalogStoreActions.LoadAllAction())),
).subscribe();
this.catalogs$ = this.catalogStore.select(CatalogStoreSelectors.selectAllCatalogs);
}
catalog$ 将是 Observable<ViewCatalog[]>
这是第一个数据集。
view-catalog.ts
export declare class ViewCatalog {
code: string;
title: string;
lastModified: string;
}
对于每个catalog,您可以通过catalog code 请求其项目
private getCatalogItems(catalogCode: string) {
this.catalogStore.dispatch(new CatalogStoreActions.GetCatalogItems({catalogCode: catalogCode}));
this.catalogItemsStore.select(CatalogItemStoreSelector.selectLoadingByCatalogSuccess)
.pipe(
takeWhile(() => this.alive),
take(1),
filter(loadSuccess => !loadSuccess),
tap(() => this.catalogItemsStore.dispatch(new CatalogItemStoreAction.LoadByCatalog({catalogCode: catalogCode}))),
).subscribe();
this.catalogItems$ = this.catalogItemsStore.select(CatalogItemStoreSelector.selectByCatalogCode(catalogCode));
}
这是第二个数据集。
public catalogItems$: Observable<CatalogItem[]>;
CatalogItem.ts
export class CatalogItem {
constructor(public code: string,
public catalogCode: string,
public title: string,
public data: object) {
}
}
我需要将所有这些数据合并到一个常见的平面列表中,如下所示:
[
catalog: {
code: "Code 1",
title: "Catalog title 1",
lastModifie": "",
parent: null,
hasChildren: true
}
catalog-item: {
code: "CatalogItem 1",
catalogCode: "Code 1",
parent: "Code 1",
hasChildren: false,
title: "CatalogItem title 1"
},
catalog-item: {
code: "CatalogItem 2",
catalogCode: "Code 1",
parent: "Code 1",
hasChildren: false,
title: "CatalogItem title 2"
},
catalog: {
code: "Code 2",
title: "Catalog title 2",
lastModifie": "",
parent: null,
hasChildren: true
},
catalog-item: {
code: "CatalogItem 1",
catalogCode: "Code 2",
parent: "Code 2",
hasChildren: false,
title: "CatalogItem title 1"
},
catalog-item: {
code: "CatalogItem 2",
catalogCode: "Code 2",
parent: "Code 2",
hasChildren: false,
title: "CatalogItem title 2"
},
]
有人可以帮助实现这一目标吗?
【问题讨论】:
标签: angular typescript rxjs observable