如何向 FormData 追加嵌套对象
如何使用表单附加来发布此数组:
data = [
{
"title":"title 1",
"subTitle": "subTitle 1",
"productId": "[1,2,3]"
},
{
"title":"title 2",
"subTitle": "subTitle 1",
"productId": "[4,5,6]"
},
{
"title":"title 3",
"subTitle": "subTitle 1",
"productId": "[7,8,9]"
}
]
如果我按如下方式提交数据: formData.append("data", JSON.stringify(this.data); 我无法仅获取值productId 中的id 键
how can post this array with form append:
data = [
{
"title":"title 1",
"subTitle": "subTitle 1",
"productId": "[1,2,3]"
},
{
"title":"title 2",
"subTitle": "subTitle 1",
"productId": "[4,5,6]"
},
{
"title":"title 3",
"subTitle": "subTitle 1",
"productId": "[7,8,9]"
}
]
If I submit data as here : formData.append("data", JSON.stringify(this.data);
I cannot get just id key in value productId
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试这个
- 在后端,您需要解析它以发送到前端。
You can try this-
and in the backend, you need to parse it for sending to the front end.
一旦你的数组被“stringify”,你需要使用 JSON.parse 来访问单个键
同时查看你的数组,你将必须使用数组键这样做
,然后从那时提取数组
如果你需要,请告诉我有关它的更多信息
Once your array has been "stringify" you need to use JSON.parse to access individual key
Also looking at your array it you will have to do it like this with the array key
and from that point extract the array
Let me know if you need more info on it