我正在挑选一份医生名单,我想在农村地区的一个部门进行分组。然后将选定的医生推入数组并保存到数据库中。我可以选择和张贴保存在数据库中,但有一点缺陷,我发现很难解决。我的问题是,当我选择1博士和2博士,并邮寄到我的服务,派到我的服务是3。即医生1,医生2,医生2。为什么博士2被复制?
选择医生
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 => {
});
}
发布于 2017-05-12 02:35:52
看起来这里有一些奇怪的变异和不必要的方法,结果是不可预测的。如果你只想把选定的医生分成一组,你可以这样做:
this.groups.members = [
...this.groups.members,
this.Doctors.filter(doctor => doctor.selected)
];
如果还想将医生的信息添加到hospital.details数组的第一项中,也可以添加以下内容:
let selectedDoctors = this.Doctors.filter(doctor => doctor.selected);
this.groups.members = [...this.groups.members, selectedDoctors];
for (let doctor of selectedDoctors) {
this.hospital.details['0'].id = doctor.id
this.hospital.details['0'].ward = doctor.ward
}
https://stackoverflow.com/questions/43926654
复制相似问题