我想像这样插入我的数据:
{name:john,address:[{houseName:gbu,place:vypin,pin:3322}]}
但是当我使用req.body
变得像这样的ajax发布这个
{name:john,address[0][houseName]:gbu,address[0][place]:vypin,address[0][pin]:3322}
建议我有任何简单的方法
答案 0 :(得分:0)
你需要在一个新的变量中重写json:
var json = {
name: req.body.name,
address: []
};
req.body.address.forEach(function (address) {
json.address.push({
houseName: address.houseName,
place: address.place,
pin: address.pin
});
});