无法读取属性';forEach&x27;未定义Nodejs/ejs/javascript的
我面临两天无法读取属性“forEach of undefined”的错误,我无法解决这个问题。你的帮助会很有帮助的。下面的代码 bruidstaart.js页面,我想在其中显示一些数据无法读取属性';forEach&x27;未定义Nodejs/ejs/javascript的,javascript,node.js,express,ejs,Javascript,Node.js,Express,Ejs,我面临两天无法读取属性“forEach of undefined”的错误,我无法解决这个问题。你的帮助会很有帮助的。下面的代码 bruidstaart.js页面,我想在其中显示一些数据 <div class="table-wrapper"> <table class="table table-hovered"> <thead class="thead-dark"> <
<div class="table-wrapper">
<table class="table table-hovered">
<thead class="thead-dark">
<tr>
<th scope="col">Image</th>
<th scope="col">Bruidstaartnaam</th>
<th scope="col">Aantalpersonen</th>
</tr>
</thead>
<tbody>
<% bruidstaarten.forEach((bruidstaart, user) => { %>
<tr>
<td><img src="/assets/bruidstaartenmap/<%= bruidstaart.image %>" class="rounded-circle player-img" alt="" width="200" height="200"></td>
<td><%= bruidstaart.bruidstaartnaam %></td>
<td><%= bruidstaart.aantalpersonen %></td>
</tr>
<% }) %>
</tbody>
</table>
</div>
我通过检查数据库中的查询和选项卡来解决这个问题。id错误,因为创建了选项卡forEach仅适用于数组,所以请检查bruidstaarten的值是多少?如果是数组或非数组,是否确定结果的类型为array,并且其中包含有效数据?此外,为了正确处理错误,您应该检查err是否包含任何内容。也许它也会告诉你问题所在。很可能
结果
未定义,bruidstaarten
-通过评估错误
,检查查询是否成功……对于此问题和未来的问题,您可能会发现有用的信息。正如@eol所说,result
可能未定义,请检查index.js中的err
。你好,eol、Dcoder和Joe Pi,我发现了问题。数据库中的id错误。创建tabel时是我的错。非常感谢你的帮助。现在可以用了
exports.bruidstaartenPage = function(req, res, next){
var sql1 = "SELECT * FROM `bruidstaarten` ORDER BY id ASC"; // query database to get all the players
db.query(sql1, function(err, result){
res.render('bruidstaartenPage', {bruidstaarten:result});
});
};