Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Can't get fields on display.ejs. I only get empty rows

Here is my controller. I can get data that is already in the database but problem is that data cant appear in my view.

const Comment = require('../models/comments.js');

exports.getComments = (req, res, next) =>{
    Comment.fetchAll()
        .then(rows => {
            res.render('display', {
                data: rows,
            });
            console.log(rows)
        })
        .catch(err => console.log(err));
};

And here is my view

 <% if(data.length > 0) { %>
        <table class="table">
            <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">Name</th>
                    <th scope="col">Email</th>
                    <th scope="col">Comment</th>
                </tr>
            </thead>
            <tbody>
            <% for(var i = 0; i< data.length; i++) { %>
                <tr>
                    <th scope="row"><%= (i+1) %></th>
                    <td><%= data[i].name%></td>
                    <td><%= data[i].email%></td>
                    <td><%= data[i].comment%></td>
                </tr>
            <% } %>
            </tbody>
        </table>
        <% } %>
        
        <!-- if result is empty -->
        <% if(!data.length) { %>
           <p class="text-center">No comments found!</p> 
        <% } %>

I don't know why I'm getting empty fields in the view because when i console.log(rows) I get data.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Problem was my view was expecting an array [rows] . So I had to pass an array as callback.

exports.getComments = (req, res, next) =>{
    Comment.fetchAll()
        .then(([rows]) => {
            res.render('display', {
                data: rows,
            });
            console.log(rows)
        })
        .catch(err => console.log(err));
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!