我有一个表单,其中有像name
,email
,other[a]
,other[b]
这样的字段,这是由AJAX提交的.目前,在使用Axios进行发布之前准备数据的脚本执行此操作
const data = Array.from(new FormData(this.form).entries()).reduce((memo, pair) => ({
...memo,
[pair[0]]: pair[1],
}), {});
它产生了
{
"name":"X",
"email":"Y",
"other[a]":"A",
"other[b]":"B",
}
但它必须是
{
"name":"X",
"email":"Y",
"other": {
"a": "A",
"b": "B"
}
}
我需要做什么才能使这other
个字段成为一个嵌套数组?