[英]How to send value with URL in ejs template
I want to send a value with the help of which i get from my database我想在我从数据库中获得的帮助下发送一个值
<% pp.forEach(function(a){ %>
<h1><a href="/users/gotospecific/{a.title}"><%= a.title %></a></h1>
but due to some problem error occured.但由于一些问题发生了错误。
can someone guide me about the problem?有人可以指导我解决这个问题吗?
If you want to use the following on your server:如果您想在您的服务器上使用以下内容:
app.get('/gotospecific', function(req, res) {
var topic = req.query.topic;
...
})
then you'll need this in EJS:那么你将需要在 EJS 中使用它:
<% pp.forEach(function(a) { %>
<h1><a href="/users/gotospecific?topic=<%= a.title %>"><%= a.title %></a></h1>
<% }); %>
where pp
is assumed to be an array of objects that have title
properties.其中
pp
假定为具有title
属性的对象数组。 eg例如
res.render('myview', {pp: [{title: 'First item'}]});
The right syntax for ejs is : ejs 的正确语法是:
<% pp.forEach(function(a){ %>
<h1><a href="/users/gotospecific/"+<%= a.title %>+""><%= a.title %></a></h1>
<% }); %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.