我已经使用了角度CLI 6和firebase。

我有两个接口类:pps和ppsplan。

export class PPS { constructor (
public Patientid : string,
public traitement: string,
public description: string,
public effetsind,
public ppsplan,
public Esresp: string,
public medresp: string,
public contactmail:string,
public contacttel: string
) {}
        }

export class Ppsplan { constructor(
public typetraitement:string,
public acte:string,
public duree:number,
public datedebut = new Date(),
public datefin = new Date()
) {} }


我将ppsplan记录在pps中作为数组。

javascript - 从观察得到有趣的领域-LMLPHP

我想得到:

this.data1 = [
["typetraitement", "enddate", "end date"],
["value1.typetraitement", "value1.datedebut", "value1.datefin"],
["value2.typetraitement", " value2.datedebut "," value2.datefin "]
    ]


当我浏览对象pps时,我想找到ppsplan数组中包含的与funcFeilds相对应的值。

零件

ngOnInit() {

this.ppssToDisplay = this.ppssService.getPPSByPatientid(this.patientid);
 let interestingFields = [ 'typetraitement','datedebut', 'datefin'];
   this.ppssToDisplay.subscribe(ppsList => {
   this.data1 = [
   interestingFields,
   ...ppsList.map(pps => interestingFields.map(field =>pps[field]))
   ];
   });
   this.config1 = new GanttChartConfig( '',new Date (),new Date ());
   this.elementId1 = 'myGanttChart';
   }


服务

getPPSByPatientid(Patientid: string){
return this.database.list('/ppss', ref => ref.orderByChild("Patientid").equalTo(Patientid)).snapshotChanges().pipe(map(actions => {
  return actions.map(a => {
    const data = a.payload.val();
    const key = a.payload.key;
    return {key, ...data };
  });
})); }


我的订阅无效。
    console.log(this.data1)说我

(2) [Array(3), Array(3)]
0:(3) ["typetraitement", "datedebut", "datefin"]
1:Array(3)
0:undefined
1:undefined
2:undefined

最佳答案

根据您的结构,似乎您正在订阅ppss,但希望获得pps列表。您的订阅不应该返回ppss,然后从pps.ppsplan数组中获得ppsList?

每个PPS对象都将包含一个对象,该对象模拟索引为'0','1'等的数组。您将需要使用Object.keys遍历对象的属性,以获取各个Ppsplan对象。

关于javascript - 从观察得到有趣的领域,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51901671/

10-10 11:31