使用NodeJS和EJS呈现MySQL查询

时间:2015-03-10 15:20:26

标签: javascript html mysql node.js ejs

我的目标是将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();
  });

我不知道我的代码中有什么内容。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

这样做:

  <% data.forEach(function(ind){ %>
    <li><%= JSON.stringify(ind) %></li>
  <% }) %>