0
我正在選擇一個醫生列表,我想在農村地區的一個部門進行分組。然後將選定的醫生推入陣列並保存到數據庫中。我可以選擇併發布以保存在數據庫中,但是我發現有一些缺陷難以解決。 我的問題是,當我選擇醫生1和醫生2併發布到我的服務,發送到我的服務的參數被計爲3.這是醫生1,醫生2,醫生2.爲什麼醫生2被複制?Http Post Json - 陣列
選擇醫生
selectDoctors(Doctors){
Doctors.listed = (Doctors.listed) ? false : true;
this.deptList = Doctors
}
提交選定醫生的組中的陣列
Doctors: Doctors[] = [];
hospital = {
hospital_name : "",
details : [{
id: "",
ward: "",
}]
}
//submit data into array
Object.keys(this.Doctors).filter(key => this.Doctors[key].selected)
.forEach(key => {
this.hospital.details['0'].id = this.Doctors[key].id
this.hospital.details['0'].ward =this.Doctors[key].ward
this.groups.members.push(this.Doctors.['0']);
}
this.http.categorizeDepartment(this.groups)
.subscribe(data => {
});
}
你可以plase console.log()內的forEach部分,看看它得到迭代3次嗎? – zenwraight
你也試圖用數組中的最後一名醫生覆蓋hospital.details嗎?或者,您是否打算將每個醫生的ID和病房添加到陣列中的單獨對象中? – Eeks33