Using ngrx, I get two data sets from storage.
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);
}
The catalog$
will be Observable<ViewCatalog[]>
This is the first data set.
view-catalog.ts
export declare class ViewCatalog {
code: string;
title: string;
lastModified: string;
}
Also for each of the catalog
, you can request its items by 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));
}
This is the second data set.
public catalogItems$: Observable<CatalogItem[]>;
CatalogItem.ts
export class CatalogItem {
constructor(public code: string,
public catalogCode: string,
public title: string,
public data: object) {
}
}
I need to combine all this data into one common flat list that would look something like this:
[
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"
},
]
Can someone help achieve this?