我有EJS文件,我想在其中传递MySQL数据库中的数据。我的代码如下所述
我的JavaScript文件
module.exports={
printSlipPage:(req, res)=>{
let trans1ID = req.param.id;
let query = "SELECT * from trans1 WHERE trans1.Sr_NO = '"+ trans1ID +"'";
conn.query(query,(err, result)=>{
if(err){
return res.status(500).send(err);
}
res.render('printslip.ejs',{
trans1: result[0]
});
});
}
}
我的EJS文件
printslip.ejs
<!doctype html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<div>
<table>
<tr>
<th>Sr No</th>
<td><%=trans1.Sr_NO%> </td>
</tr>
</table>
</div>
</html>
我想在视图文件中显示Sr_no的值,但出现错误
TypeError:G:\ NODE PROJECT \ t-freight \ views \ printslip.ejs:第10行是
10 | Sr No <%trans1.Sr_NO%>无法读取未定义的属性'Sr_NO'