我的目标是将来自MySQL查询的数据放入HTML表中。但是,我有以下输出:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
从这个简单的
ejs
文件中:<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<% data.forEach(function(ind){ %>
<li><%= data %></li>
<% }) %>
</table>
</body>
</html>
从中获取数据
pool.query(query, function select(error, results, fields) {
var temp = "";
if (error) {
console.log(error);
pool.end();
}
res.render('index.html',{data:results, error:null});
//pool.end();
});
我不知道代码中会发生什么。有什么建议么?
最佳答案
做这个:
<% data.forEach(function(ind){ %>
<li><%= JSON.stringify(ind) %></li>
<% }) %>
关于javascript - 使用NodeJS和EJS渲染MySQL查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28967521/