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

197
Views
No se pueden obtener campos en display.ejs. Solo obtengo filas vacías

Aquí está mi controlador. Puedo obtener datos que ya están en la base de datos, pero el problema es que los datos no pueden aparecer en mi vista.

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

Y aquí está mi vista

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

No sé por qué obtengo campos vacíos en la vista porque cuando console.log(rows) obtengo datos.

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

0

El problema era que mi vista esperaba una matriz [rows] . Así que tuve que pasar una matriz como devolución de llamada.

 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!