【问题标题】:Unable to render data from my nodejs(after using select * query on mysql) to ejs page无法将我的 nodejs 中的数据(在 mysql 上使用 select * 查询后)呈现到 ejs 页面
【发布时间】:2021-01-15 04:51:06
【问题描述】:

我从 mysql db 中获取了结果,并且在我的控制台中获取了数据,但它不会在我的 ejs 页面中呈现。 这是我的 .ejs 页面代码:

<table>
<tr>
  <th>Name</th>
  <th>Date Formed</th>
  <th>Location</th>
</tr>

<%for(int i = 0;i < Allo.length; i++){%>
        <tr>
          <td><%=Allo.name%></td>
          <td><%=Allo.form_date%></td>
          <td><%=Allo.location%></td>
        </tr>
<%}%>

</table>

这是我的 app.js:


    app.get("/Teams",function(req,res){
      db.query('SELECT * FROM team',function(err,result){
        console.log(result);
        res.render("Teams",{Foo:"",Allo:result});
    
      });
    
    });

console.log(result) 工作正常。

【问题讨论】:

    标签: html mysql node.js express ejs


    【解决方案1】:

    我明白了,伙计们。使用 forEach 解决了这个问题。

    <% Allo.forEach(function(Allo){ %>
              <tr>
                <td><%=Allo.name%></td>
                <td><%=Allo.form_date%></td>
                <td><%=Allo.location%></td>
              </tr>
      <% })%>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      相关资源
      最近更新 更多