【发布时间】:2025-11-23 11:00:02
【问题描述】:
我想为我的网站中的帖子制作一个报告按钮,在我的帖子模型中我有:reported: ,默认值为 false,我希望如果有人单击该按钮,则该值将更改为 true。
我在html页面上的ejs:
<% posts.forEach(function(post){ %>
<% if(post.uploadedBy == Tuser){ %>
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h4 class="display-4" style="text-transform: capitalize;"><%= post.title %></h4>
<h5><%= post.uploadedBy %></h5>
<p class="lead"><%= post.text %></p>
<a href="#" onclick="reported(<%= post %>)">Report Post</a>
</div>
</div>
<% } %>
<% }) %>
我对 app.js 文件中页面的 GET:
//get someone else's blog
router.get('/othersblog/:username',(req,res) => {
Post.find({},(err,posts) => {
if(err){
console.log(err);
}else{
res.render('othersblog',{
headline: "Website | User Blog",
title: "Blog",
Tuser: req.params.username,
posts: posts,
});
}
})
});
如果你知道怎么做,请帮助我。谢谢。
【问题讨论】:
-
我更新了我的答案。希望它对您有所帮助,或者让您了解如何实现目标。
-
非常感谢它的工作!