传递数据视图查询节点Express-EJS

时间:2018-12-29 11:06:36

标签: node.js express ejs

我的node.js文件中有一个查询。

如何将q2结果集CAMERA_FRIA传递到ejs文件?

// Queries 
var q1 = "SELECT DEVICEID, CAMERA_FRIA FROM DASH13476.IOT_DHT 
var q2 = "SELECT DEVICEID, CAMERA_FRIA FROM DASH13476.IOT_DHT WHERE                     
DEVICEID = 1

//query sql
conn.query(q1+";"+q2,[1,2], function (err, data) {
if (err) throw err;  

//query devices
appClient.getAllDevices(). then (function onSuccess (response) {
res.render('pages/dashboard', {
camera_fria_all: data[0], (pass all results ok)
camera_fria_last: data[1].CAMERA_FRIA  (would like to pass only 
`enter code here`CAMAERA_FRIA result set ??)
});
}, function onError (argument) {
console.log("Fail");
console.log(argument);
res.render('pages/error', {
message: "Something wrong happen.",
detail: argument
});
});

//IN ejs file (how can I read q2 camera_fria here in my ejs?)
<div>Camera Fria (oC)</div> 
<div><%= xxxx %></div>  ???

1 个答案:

答案 0 :(得分:0)

您在NullPointerException对象上设置的所有内容(res.locals函数的第二个参数)将可用于其模板(第一个参数)。因此,您的“页面/仪表板”模板可以直接访问res.rendercamera_fria_all

camera_fria_last