【发布时间】:2021-11-13 12:33:44
【问题描述】:
我的后端有这个功能:
app.get('/dashboard', async(req, res) => {
const customers = await stripe.customers.list();
customers.data.forEach(customer => {
console.log(customer.metadata);
});
res.render('dashboard.ejs', {customer: customers})
})
在我的前端:
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>NAME</th>
<th>EMAIL</th>
<th>ACTIONS</th>
</tr>
</thead>
<tbody>
<% if(customer.length){
for(var i = 0;i < customer.length;i++) { %>
<tr>
<td><%=customer[i].NAME%></td>
<td><%=customer[i].EMAIL%></td>
<% }
}else{ %>
<% } %>
</tbody>
</table>
但是,我正在尝试将 METADATA 传递给前端。在元数据对象中,我有name 和email。所以在前端,我尝试了:
<%=customer[i].METADATA.NAME%>
但它什么也没返回。和后端相同。我该如何解决这个问题?
【问题讨论】:
-
你得到什么错误?
undefiened或error 404, 404, 500 ... -
@span 没有错误。它只是不返回任何东西。它是空的。但是当我登录
customers.data.forEach(customer => { console.log(customer.metadata); });时,它会显示元数据,但现在我需要将该元数据发送到前端 -
在 Javascript 中,对象键区分大小写,您说您的数据中有
name和email,但在模板中您使用了.NAME和.EMAIL -
你也不见了
-
哦,你需要确定。我将尝试添加有关如何获取的代码。
标签: javascript node.js for-loop ejs