1
我要發佈嵌套支柱件的NodeJS - 快 - 嵌套後數據未解析正確
查看HTML形式
<form method="post" action="">
<input type="text" placeholder="Enter Tag here" class="gui-input" name="reply_message">
<input type="text" placeholder="Enter Label for Decision" class="gui-input" name="decision[0][label]" value="Interested">
<input type="text" placeholder="Enter decision keywords here" class="gui-input" data-role="tagsinput" name="decision[0][keyword]" value="Interested, call me">
<input type="text" placeholder="Enter Label for Decision" class="gui-input" name="decision[1][label]" value="Not Interested">
<input type="text" placeholder="Enter decision keywords here" class="gui-input" data-role="tagsinput" name="decision[1][keyword]" value="not interested, not">
<input type="text" placeholder="Enter Label for Decision" class="gui-input" name="decision[2][label]" value="Call Later" >
<input type="text" placeholder="Enter decision keywords here" class="gui-input" data-role="tagsinput" name="decision[2][keyword]" value="Interested, call me, later">
<button class="button btn-primary" type="submit">Submit </button>
路由器文件
router.post('/mapping', isLoggedIn, function (req, res, next) {
var posted_data= req.body;
console.log(req.body);
res.send(posted_data);
});
我得到像這樣的發佈數據結構
{
"reply_message": "This is test",
"decision[0][label]": "Interested",
"decision[0][keyword]": "Interested, call me",
"decision[1][label]": "Not Interested",
"decision[1][keyword]": "not interested, not",
"decision[2][label]": "Call Later",
"decision[2][keyword]": "Interested, call me, later"
}
但實際發佈的數據結構應該是
{
"reply_message": "This is test",
"decision": [{
"label": "Interested",
"keyword": "Interested, call me"
}, {
"label": "Not Interested",
"keyword": "not interested, not"
}, {
"label": "Call Later",
"keyword": "Interested, call me, later"
}]
}
因此,如何CA我做到這一點,是否有任何節點模塊我必須使用像這樣發佈表單數據?
您使用的是舊版本Express和/或'身體parser'的? 'body-parser'的默認配置會自動解析該輸入。請參閱['extended'選項](https://www.npmjs.com/package/body-parser#extended)。 – robertklep
我正在使用最新版本的兩個...我必須使用擴展選項來以嵌套方式解析。 –
我正在鏈接的那個,這是默認的。但是,由於表單的「操作」是空的,我假設您正在使用某種客戶端代碼來提交數據?你確定這樣做沒問題嗎?例如,你沒有提交任何機會的數據作爲JSON? – robertklep