这里我传递id
,它存储在m
中,请帮助我如何传递id
。并使用该 id
调用该页面。我正在使用嵌入式 JavaScript 模板作为 View 引擎,请帮忙。
$.each(products, function(index, product ) {
var m= product['_id'];
//document.write(alert(m));
string += '<tr><td>'+(index+1)+'</td><td>'+product['_id']+'</td><td>'+product['name']+'</td><td>'+product['category']+'</td><td>'+product['price']+'</td><td>'+product['manufacturer']+'</td><td><a href="/profile/dashboard/update/{{m}}">Update</a> </td></tr>';
});
route code
app.get('/profile/dashboard/update/:m',function (req,res,next) {
console.log("hi"+req.params.m);
});
最佳答案
string += '<tr><td>'+(index+1)+'</td><td>'+product['_id']+'</td><td>'+product['name']+'</td><td>'+product['category']+'</td><td>'+product['price']+'</td><td>'+product['manufacturer']+'</td><td><a href="profile/dashboard/update/'+id+'">Update</a> </td></tr>';
它会起作用
关于node.js - Node.js如何传递变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52146640/