所以我有一个 API,我试图从中使用数据。正在重新调整的数据:
组织
baseId: 1
createdAt: "2018-11-14T04:35:35.345Z"
id: 1
isActive: true
orgName: "Test Organization 1"
orgOwner: 2
subscriptionCode: "testorg1"
updatedAt: "2018-11-14T04:35:35.34
根据
bandwidthApiSecret: "xxxxxx"
bandwidthApiToken: "t-xxxxxx"
bandwidthUserId: "u-xxxxxx"
baseName: "Test AFB 1"
basePhoneNumber: "+18442367381"
createdAt: "2018-11-14T04:35:35.123Z"
id: 1
isActive: true
updatedAt: "2018-11-14T04:35:35.123Z"
我想做但无法理解的是使用 rxjs 操作在需要的地方插入组织。因此,如果一个基地有一个或多个组织,则应将其插入基地。这是我的界面:
基础接口
import { Organization } from './organization';
import { BaseManager } from './base-manager';
export interface Base {
id: number;
basePhoneNumber: string;
baseName: string;
bandwidthUserId: string;
bandwidthApiToken: string;
bandwidthApiSecret: string;
createdAt?: Date;
updatedAt?: Date;
orgs?: Organization;
managers?: BaseManager;
}
组织界面
export interface Organization {
id: number;
orgName: string;
orgOwner: string;
baseId: number;
subscriptionCode: string;
isActive: boolean;
createdAt: Date;
updatedAt: Date;
}
我发现这个JSBin看起来像是在做我需要完成的事情。由于我对这个主题缺乏理解,我无法让它发挥作用。这是我的 Angular 组件的片段:
import { Component, OnInit } from '@angular/core';
import { Base } from 'src/app/core/interfaces/base';
import { BaseService } from 'src/app/core/services/base.service';
import { OrgService } from 'src/app/core/services/org.service';
import { Organization } from 'src/app/core/interfaces/organization';
import { switchMap } from 'rxjs/operators';
@Component({
selector: 'app-base-list',
templateUrl: './base-list.component.html',
styleUrls: ['./base-list.component.css']
})
export class BaseListComponent implements OnInit {
bases: Base[];
orgs: Organization[];
constructor(private baseService: BaseService, private orgService: OrgService) { }
ngOnInit() {
this.loadOrgs();
this.loadBases();
}
loadBases() {
this.baseService.getAllBases()
.subscribe(
res => {
this.bases = res['bases'];
console.log(this.bases);
}
);
}
// loadBases(): Base[] {
// this.baseService.getAllBases()
// .subscribe(
// res => {
// this.bases = res['bases'].pipe(
// switchMap( base => {
// return this.getOrg(base.id).map(
// base => {
// return Object.assign(base, {base, {org: this.orgs});
// }
// )
// })
// );
// });
// }
loadOrgs() {
this.orgService.getOrgs()
.subscribe(
res => {
this.orgs = res['orgs'];
console.log(this.orgs);
}
);
}
getOrg(baseId) {
this.bases.filter(base => base.id === baseId);
}
}
任何有关此事的帮助将不胜感激。
干杯,
教练