我正在使用以下内容将表单转换为 JS 对象,然后将其插入到 MongoDB 集合中......
form={};
$.each($('#myform').serializeArray(), function() {
form[this.name] = this.value;
});
这会产生以下内容:
{ "name" : "value", "name" : "value", "name" : "value", "name" : "value" }
我想得到类似的东西:
{
"aaa": "111",
"bbb": "222",
"ccc": "333",
"loc": {
"longitude": "-11.34354656",
"latitude": "-45.4566546"
}
}
我应该如何修改 jQuery 来获得它?我看到有用于这项工作的插件,但我想知道解决方案是否比这更简单..?