我想通过传入变量在EJS中动态创建href。
在app.js中,我有:
var pivotTable = {};
app.get('/pivot', function(req, res){ // /'pivot'' is the path in browser
var link = "'/user' + item.eventusername";
db.query('SELECT *, ROUND(TotalAgreed/Good*100,2) AS Conversion FROM precursor'
, function(err, result) {
if(err){
throw err;
} else {
pivotTable = {data: result, link: link};
res.render('pivot', pivotTable); //Rendering the view 'lifecycle'
}
});
});
在ivot.ejs中,我有:
<tbody>
<% data.forEach(function (item) { %>
<tr>
<td><p><a href="<%= link %>"><%= item.eventusername %></a></p></td>
</tr>
<% }) %>
</tbody>
此链接尝试解决:
http://localhost:5000/'/user%27%20+%20item.eventusername
如何获取该href链接来解决:
http://localhost:5000/user/content-Of-item.eventusername
谢谢