如何嵌套表单数据
How to nest form data
我想要以下 json 示例:
{
attachments: {
file: [
{ name: 'pic1.jpg' },
{ name: 'pic2.png' }
],
username: 'Test',
age: 1
}
}
这在表单数据中可能吗?
好的,我明白了。只需在数组键之前传递另一个键...例如:
fd = new FormData();
const files = [{...}, {...}, ...]
files.map(file => {
fd.append("attachments[] file[]", file.name)
});
fd.append("attachments[] name", 'Test')
fd.append("attachments[] age", 1)
我想要以下 json 示例:
{
attachments: {
file: [
{ name: 'pic1.jpg' },
{ name: 'pic2.png' }
],
username: 'Test',
age: 1
}
}
这在表单数据中可能吗?
好的,我明白了。只需在数组键之前传递另一个键...例如:
fd = new FormData();
const files = [{...}, {...}, ...]
files.map(file => {
fd.append("attachments[] file[]", file.name)
});
fd.append("attachments[] name", 'Test')
fd.append("attachments[] age", 1)