我已经使用了角度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中作为数组。
我想得到:
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
答案 0 :(得分:2)
根据您的结构,似乎您正在订阅ppss,但希望获得pps列表。您的订阅不应该返回ppss,然后从pps.ppsplan数组中获得ppsList?
每个PPS对象都将包含一个 object ,该对象将模拟索引为'0','1'等的数组。您将需要使用Object.keys来迭代对象的属性。对象以获取各个Ppsplan对象。
答案 1 :(得分:0)
我做了这个,但是现在,当我添加一个数据时,我的数据被复制了。
ngOnInit() {
this.route.params.forEach((urlParameters) => {
this.patientid = urlParameters['id'];});
this.patientToDisplay = this.patientsService.getSinglePatient(this.patientid);
this.diagnosticsToDisplay = this.diagnosticsService.getDiagnosticByPatientid(this.patientid);
this.ppssToDisplay = this.ppssService.getPPSByPatientid(this.patientid);
this.sossToDisplay = this.sossService.getSOSByPatientid(this.patientid);
this.ppsdocsToDisplay = this.docsService.getPpsDocByPatientid(this.patientid);
let interestingFields = [ 'typetraitement','datedebut', 'datefin'];
let data1=[interestingFields];
this.ppssToDisplay.subscribe((ppsList: PPS[]) => {
console.log(ppsList);
ppsList.map((pps: PPS) => {
Object.keys(pps.ppsplan).forEach(key => {
let ppsplan: Ppsplan = pps.ppsplan[key];
data1.push([
...interestingFields.map(field => ppsplan[field])
]);
});
console.log(data1);
});
this.data1 = data1;
});