我正在尝试在节点js中运行,但是我的更新无法正常工作。我试图更新两天,但无法正常工作。表单成功添加和删除ID。 表格
<a href="/edit/<%= admins[i]._id %>" class="btn btn-danger">Edit</a>
<form action="/edit" method="POST" id="myForm">
<div class="form-group">
<input type="text" class="form-control" placeholder="Title" name="title" value="<%= admins.title %>"></div>
<div class="form-group"><input type="text" class="form-control" placeholder="URL" name="url"
value="<%= admins.url %>"></div>
<div class="form-group"> <input type="text" class="form-control" placeholder="Description" name="description"
value="<%= admins.description %>"></div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Keywords" name="keywords" value="<%= admins.keywords %>">
</div>
</form>
<input type="submit" value="edit" class="btn btn-primary" form="myForm">
adminController.js
router.get('/edit', async (req,res) => {
const id = req.params;
const admins = await Admin.findById(id);
res.render('/seo', {
admins
});
});
router.get('/edit/:id', async (req,res) => {
const { id } = req.params;
await Admin.findOneAndUpdate({_id: id}, req.body, { new: true });
res.redirect('/seo');
});