gpt4 book ai didi

node.js - 从 HTML 获取动态路由输入

转载 作者:太空宇宙 更新时间:2023-11-04 00:50:18 26 4
gpt4 key购买 nike

我使用 ejs 作为模板语言。

<main class="content">
<% documents.forEach(function(documentObject) { %>
<h1><a href="/showprofile/:username"><%= documentObject.username %></a> solved </h1>
<h2><%= documentObject.problem_id %>. <%= documentObject._statement %> in
<%= documentObject.time %> seconds on
<%= documentObject.date_added %> . </h2>
<% }) %>


</main>

我正在使用动态路由 /showprofile/:username 进行重定向。我需要以这样的方式创建超链接,以便将 documentObject.username 的值作为参数传递给 :username 。我怎样才能做到这一点?

最佳答案

您只需使用 ejs 函数在 href 属性中呈现用户名,而不是 :username:

<h1><a href="/showprofile/<%= documentObject.username %>"><%= documentObject.username %></a> solved </h1>

关于node.js - 从 HTML 获取动态路由输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32920528/

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