我目前正在从udemy那里寻求一个关于node js的课程,所以我一直在使用NodeJS、MongoDB、Mongoose、Express、Express-Handlebar开发CRUD应用程序。每当我尝试编辑帖子时,我无法获得编辑form...some帮助上的值,我将不胜感激
我已经找了一遍又一遍我能找到的所有可能的解决方案,但都不起作用!
单击按钮时转到编辑页面的NodeJs代码
//Ideas Edit
app.get("/ideas/edit/:id", (req, res) => {
Idea.findOne({
_id: req.param.id
}).then(idea => {
res.render("ideas/edit", {
idea: idea
});
});
// .catch(err => console.log(err));
});编辑表单页面
<div class="card card-body">
<h1>Edit Video Idea</h1>
<form action="/ideas" method="POST">
<div class="form-group">
<label for="title">Title</label>
<input type="text" name="title" class="form-control" value="{{idea.title}}" />
</div>
<div class="form-group">
<label for="details">Details</label>
<input type="text" name="details" class="form-control" value="{{idea.details}}" />
</div>
<button class=" btn btn-primary">Submit</button>
</form>
</div>我无法以"value="{{idea.title}}“”的形式获取正在编辑的当前帖子的值。作为教程,它是正确的,但不起作用
发布于 2019-06-11 23:29:12
如果你使用的是ejs模板,那么你可以这样写:
<input type="text" name="title" class="form-control" value="<%=idea.title%>" />https://stackoverflow.com/questions/56543870
复制相似问题