【发布时间】:2018-04-26 04:53:45
【问题描述】:
我无法通过 HTML 表单将对象传递到我的 PUT 路由。当我尝试 console.log 终端读取未定义的“产品”对象时。如果我不尝试将数据作为对象传递,我已经安装了 Method Override 并且一切正常。例如名称=“标题”和名称=“价格”。
app.js
router.put('/events/:id', function(req, res){
console.log(req.body.product);
res.redirect('/events/');
});
HTML
<form action="/events/<%= product._id %>?_method=PUT" method="POST">
<div class="form-group">
<input class="form-control" type="text" name="product[title]" value="<%= product.title%>">
</div>
<div class="form-group">
<input class="form-control" type="text" name="product[price]" value="<%= product.price%>">
</div>
<div class="form-group">
<button>Submit</button>
</div>
</form>
【问题讨论】:
-
哦!它被设置为假。现在工作。谢谢!