首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Http Post Json - Array

Http Post Json - Array
EN

Stack Overflow用户
提问于 2017-05-11 22:35:37
回答 1查看 59关注 0票数 0

我正在挑选一份医生名单,我想在农村地区的一个部门进行分组。然后将选定的医生推入数组并保存到数据库中。我可以选择和张贴保存在数据库中,但有一点缺陷,我发现很难解决。我的问题是,当我选择1博士和2博士,并邮寄到我的服务,派到我的服务是3。即医生1,医生2,医生2。为什么博士2被复制?

选择医生

代码语言:javascript
运行
复制
 selectDoctors(Doctors){
            Doctors.listed = (Doctors.listed) ? false : true;
            this.deptList = Doctors

        }

提交数组中选定的医生组

代码语言:javascript
运行
复制
     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 => {

});

}
EN

回答 1

Stack Overflow用户

发布于 2017-05-12 02:35:52

看起来这里有一些奇怪的变异和不必要的方法,结果是不可预测的。如果你只想把选定的医生分成一组,你可以这样做:

代码语言:javascript
运行
复制
this.groups.members = [
   ...this.groups.members,
   this.Doctors.filter(doctor => doctor.selected)
];

如果还想将医生的信息添加到hospital.details数组的第一项中,也可以添加以下内容:

代码语言:javascript
运行
复制
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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43926654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档