【问题标题】:Firebase returned value not rendering in ejsFirebase返回的值不在ejs中呈现
【发布时间】:2021-12-09 22:19:45
【问题描述】:

在我的 ejs 中,我有这个代码:

 <% for(var bill in ChildData){ %>
    <tr>
       <td><%= bill.id %></td>
       <td><%= bill.Phone %></td>
       <td><%= bill.Amount %></td> 
       <td><%= bill.Purchase_Date %></td>
       <td>View Details</td>
    </tr>
 <% } %>

在我的节点中

app.get("/viewbill", function(req,res){
    database.once("value", function (snapshot) {
        res.render('viewbills', {ChildData: snapshot.val()});    
    });
})

但是在我获得的页面上 Screenshot of the output I get

即使我尝试得到相同的结果

<td><%- JSON.stringify(bill.id) %></td>

【问题讨论】:

  • 你在res.render之前尝试过console.log(snapshot.val())
  • 是的,我确实尝试过 console.log(snapshot.val()) 并且我得到了值,但它只是没有在 ejs 中呈现。
  • ejs里面的console.log如何确保
  • 是的,当我在 ejs 中使用 console.lo 时,它会在终端中显示数据
  • 你能发个ss吗。我不知道出了什么问题

标签: javascript node.js firebase-realtime-database ejs


【解决方案1】:

将 ejs 代码更改为此给了我输出

<% Object.keys(ChildData).forEach(function(key) { %>
                <tr>
                    <td><%- ChildData[key].id %></td>
                    <td><%- ChildData[key].Phone %></td>
                    <td><%- ChildData[key].Amount %></td> 
                    <td><%- ChildData[key].Purchase_Date %></td>
                    <td>View Details</td>
                </tr>
              <% }); %>   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    相关资源
    最近更新 更多