无法将数据从我的nodejs(在mysql上使用select*查询后)呈现到ejs页面



我从mysqldb中获取了结果,并在控制台中获取了数据,但它不会在我的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(结果(运行良好。

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

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

最新更新