我试图通过点击表格行从动态快速路线获取唯一ID。检查行时id存在但单击它返回undefined。这是我的代码。
PUG(JADE):
.row
.col-xs-12
.box
.box-header
h3.box-title Staging Campaigns
.box-body
table.table.table-bordered.table-hover(name="stagingCampaigns")
thead
tr
th Campaign Name
th Associated Business
th Total Budget
tbody
mixin stagingCampaigns(campaignID,name,associatedBusiness,budget)
tr.clickable-row(href='/management/' + campaignID)
td=name
td=associatedBusiness
td=budget
for campaign in stagingCampaignsArray
+stagingCampaigns(campaign.id,campaign.name,campaign.associatedBusiness,campaign.budget)
NODE:
app.get('/management/:campaignID',passportConfig.isAuthenticated, mainController.getCampaign);
exports.getCampaign = (req, res) => {
// create new campaign for brand
console.log(req.params);
if(req.user.accountType === "manager") {
Campaign.findById(req.params.campaignID, (err, campaign) => {
if (err)
{
//console.log(err);
}
else
{
res.render('management/newAd', {
title: 'Home',
Campaign:campaign
});
}
});
}
}
答案 0 :(得分:0)
当你拨打campaign.id
mixin时,你对stagingCampaigns
参数感到不满吗?也许您需要使用campaign._id
?
+stagingCampaigns(campaign._id,campaign.name,campaign.associatedBusiness,campaign.budget)