Tengo un problema con la iteración de objetos en EJS. Estoy conectado a una base de datos en el backend, y puedo registrar los objetos en la consola, pero cuando lo ejecuto a través del front-end, obtengo un resultado de [Objeto]
Aquí está el código en mi código en el backend
app.get('/usageData', (req, res) => { tableSvc.queryEntities('usageData', query, null, function (error, result, response) { if (!error) { Object.keys(result).forEach(function(key){ const final=result[key] res.render("usage",{final}) }) } else { console.log(error) } }); });Y en EJS:
<ul> <table > <table class="table table-hover"> <thead> <tr class="indexs"> <th scope="col">PartitionKey</th> <th scope="col">RowKey</th> <th scope="col">Action</th> <th scope="col">SelectedReports</th> <th scope="col">reportInterval</th> </tr> </thead> <tbody> <tr> <% for(var i in final) { %> <tr style="font-size: 15px"> <td><%= final[i].PartitionKey %> </td> <td><%= final[i].RowKey %> </td> <td><%= final[i].Action %> </td> <td><%= final[i].SelectedReports %> </td> <td><%= final[i].reportInterval %> </td> </tr> <% } %> </tr> </tbody> </table> </table> </ul> 
En lugar de llamar a res.render() en cada iteración de ciclo, cree una matriz de datos y páselo solo una vez
if (error) { console.error(error) return res.status(500).send(error) } res.render("usage", { final: Object.values(result) }) Además, no use for..in para iterar matrices
<tbody> <% for(const usage of final) { %> <tr style="font-size: 15px"> <td><%= usage.PartitionKey %> </td> <td><%= usage.RowKey %> </td> <td><%= usage.Action %> </td> <td><%= usage.SelectedReports %> </td> <td><%= usage.reportInterval %> </td> </tr> <% } %> </tbody>