2017-02-27 52 views
0

我想從動態快速路由中獲取一個唯一的ID,從點擊一個表格行。在檢查行時該id存在,但點擊它返回未定義。這是我的代碼。表示動態url req.params返回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

你舒爾約campaign.id參數,當你調用stagingCampaigns混入?也許你需要使用campaign._id

+stagingCampaigns(campaign._id,campaign.name,campaign.associatedBusiness,campaign.budget)