【发布时间】:2021-12-23 10:51:08
【问题描述】:
我在 EJS 上迭代对象时遇到问题。我连接到后端的数据库,我可以控制台记录对象,但是当我通过前端运行它时,我得到 [Object] 的结果
这是我后端代码中的代码
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)
}
});
});
在 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>
【问题讨论】:
-
不要在
forEach中调用render函数
标签: javascript node.js express ejs