繁体   English   中英

如何在 angular 中将属性作为数组发送到后端 spring 启动

[英]how to send property as a array to backend spring boot in angular

我有以下方法,我试图将一些值作为列表发送到我的后端。 接受的 json 格式如下:

{
value: [xyz]
}

但现在我只将 xyz 部分作为单个值发送到我的后端,但我需要将它作为所示部分发送。 我的看起来像这样: xyz 根据在我的控制台中发送到网络后端的有效负载。

这是我用来将这些发送到后端的 function:

 setValueForTest() {
    this.personArray = this.form.controls.selectBox.value;
    this.personArraySave = []
    this.personArray.forEach((id) => {
        this.personArraySave.push(id)
        this.api.setValueForPerson({
          body: id
        
        ).subscribe(response => {
          console.log(response)
        });
      }
    });
  } 

body 和 personArraySave 来自只有 id: Array 作为属性的 Person 类型

我想 api.setValueForPerson 是一个发送数据的服务,如果是的话,也许你可以发送这样的数据

setValueForPerson(person:Person):Observable<any>{
   return this.httpCLient.post<any>(yourURL, {value:person});
}

感谢所有提供帮助的人,问题已解决我刚刚实例化了我发送的 Object 的一个元素。 然后我可以使用 model 内部的数组元素并将我的值推入其中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM