gpt4 book ai didi

html - 使用 Node 从客户端的按钮获取用户信息

转载 作者:太空宇宙 更新时间:2023-11-03 23:59:55 25 4
gpt4 key购买 nike

我正在创建一个博客网站,您可以在其中创建自己的博客并观看其他人的博客,我有一个页面,您可以在其中查看博客列表并输入每个博客,我正在使用 ejs 并使用 for 循环添加每个博客都有一个 li 标签,这里是 ejs 和 html:

<%- include('partials/header') %>
<h1><%= title %></h1>
<ul class="list-group">
<% users.forEach(function(Tuser) { %>
<% if(Tuser.id != user.id) { %>
<li class="list-group-item">
<a href="/posts/othersblog"><h5><%= Tuser.username %></h5></a>
</li>
<% } %>
<% }) %>
</ul>
<%- include('partials/footer') %>

Tuser 是除您以外的所有用户,通过单击 a 标签我想获取 Tuser 的 ID 或用户名,这是 Node 部分中的 app.post:

//get someone else's blog
router.get('/othersblog',(req,res) => {
res.render('othersblog',{
headline: "Website | User Blog",
title: "Blog",
Tuser: req.Tuser,
})
})

我如何获得 Tuser,以便我可以在其他博客页面(其他人博客)中使用它

最佳答案

您可以在路线上使用 GET 参数,如下所示:

在您的模板上:

<% users.forEach(function(Tuser) { %>
<% if(Tuser.id != user.id) { %>
<li class="list-group-item">
<a href="<%= '/posts/othersblog/' + Tuser.username %>"><h5><%= Tuser.username %></h5></a>
</li>
<% } %>
<% }); %>

然后在您的路线上:

router.get('/othersblog/:username',(req,res) => {
res.render('othersblog',{
headline: "Website | User Blog",
title: "Blog",
Tuser: req.params.username,
});
});

关于html - 使用 Node 从客户端的按钮获取用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55269067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com