【发布时间】:2019-08-21 19:39:48
【问题描述】:
我想要做的是将我的节点 js 数据从我的数据库发送到车把模板。但是当我将它发送到模板时,它显示为 [object Object]。即使在请求网页中我的数据正常显示,我也不知道为什么将其读取为 [object Object]。
我已经尝试了以下方法:JSON.parsing、JSON.stringify、GSON.parsing 和 JSON.stringify 来测试我的数据会发生什么,但使用这些方法时数据不会显示。
-------SERVER.JS-------------
app.use('/number',function(req, res){ // created an API which gets the MySQL data onto that certain web directory
db.query("SELECT * FROM qnumber",function(error,rows,fields){ //query the data with the function and its parameters
if(value <= rows.length){
value++;
const getNumber = rows[value].qNumberCount;
console.log('array: '+value +' = '+ getNumber);
console.log(getNumber);
res.render('index',{title: 'CIV Queueing System',getNumber});
// res.send(getNumber);
}
else{
console.log('Error in Query!');
console.log(error); //display in the console the specific error
}
});
});
-------index.handlebars-------------
<html>
<head>
<style>
body{background: rebeccapurple;font-family: verdana;color: whitesmoke;padding: 30px;}
h1{font-size: 48px; text-transform: uppercase; letter-spacing: 2px; text-align: center;}
p{font-size: 16px;text-align: center;}
</style>
<h1>Queue Counts</h1><br>
</head>
<body class="text-center">
<script src="/reload/reload.js">
var stringJSON = JSON.stringify({{this}});
var parseJSON = JSON.parse({{this}});
var gsonParse = gson.parse({{this}});
var gsonString = gson.stringify({{this}});
</script>
This: {{this}}<br><br>
stringGSON: {{gsonString}}<br><br>
parseGSON: {{gsonParse}}<br><br>
parseJSON: {{parseJSON}}<br><br>
stringJSON: {{stringJSON}}<br><br>
</body>
</html>
【问题讨论】:
标签: html mysql node.js json express