fieldRender(formSets: any[]) {
let questions: any[] = [];
let q: QuestionBase<any>[] = [];
let index: number = 0;
formSets.forEach(formSet => {
formSet.children.forEach(child => {
this.appointmentService.getField(child.field.uuid).subscribe(res => {
let dataType;
let label;
let parent;
let uuid;
let answers = [];
if (res.concept != null) {
if (res.concept.datatype)
dataType = res.concept.datatype.display;
if (res.answers)
answers = res.answers;
}
uuid = res.uuid;
label = res.display;
parent = formSet.parent.field.display;
let question: Question = new Question();
question.label = label;
question.type = dataType;
question.parent = parent;
question.uuid = uuid;
question.answers = answers;
questions.push(question);
console.log("Questions", JSON.stringify(questions));
});
});
});
}这是我的function.What,我希望这个函数返回可观察到的问题,我可以订阅这些问题,以便在任何地方获取数据。FormSets是包含父数组和子数组的FormSet FormSet数组
发布于 2017-09-20 19:43:33
如果formSet.children是一个数组,您可以执行类似如下的操作
Rx.Observable.from(formSet.children)
.flatMap((child) => this.appointmentService.getField(child.field.uuid))
.subscribe((question) => questions.push(question))这样,您就可以将来自getField的所有响应放在一个“流”中。
你没有给我们太多的背景信息,所以我猜;)
https://stackoverflow.com/questions/46320682
复制相似问题