简体   繁体   中英

Cannot read property 'forEach' of undefined Nodejs/ejs/javascript

Iam facing the error Cannot read property 'forEach of undefined' for two days long and I just coudn't solve the problem. Your help would be very helpful. The code below

bruidstaart.js page where I want to show some data

<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>

index.js

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});
  });
};

I figure it out by checking the query and the tabel in the database. id was wrong by creating the tabel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM