我遇到了问题。我想知道是否有办法将变量req传递给db.all函数?
app.get('/sendMail', (req, res) => {
var sql="SELECT email FROM dentists WHERE id="+req.param('id');
db.all(sql,function(err,rows){
if (err)
res.render('reponse', { err:err});
else
mailOptions={
from: 'toothFairy.noreply@gmail.com',
to: rows[0].email,
subject: 'New message from '+req.param('firstname')+' '+req/param('lastname'),
text: req.param('message')
};
});
res.render('home');
})
答案 0 :(得分:0)
是的,您可以访问,因为db.all
内部的回调无需作为参数传递,您可以直接访问
app.get('/sendMail', (req, res) => {
var sql="SELECT email FROM dentists WHERE id="+req.param('id');
db.all(sql,function(err,rows){
if (err)
res.render('reponse', { err:err});
else
mailOptions={
from: 'toothFairy.noreply@gmail.com',
to: rows[0].email,
subject: 'New message from '+req.param('firstname')+' '+req.param('lastname'),
text: req.param('message')
};
});
res.render('home');
})