这是以cart为对象(会话数组)的订单架构;
app.get('/api/profile', isLoggedIn, function(req, res, next) {
Order.find({user : req.user}, function(err, orders) {
if (err) return err;
var cart;
orders.forEach(function(order) {
cart = new Cart(order.cart);
order.items = cart.generateArray();
});
res.render('pages/profile.ejs', {orders : orders});
});
这是从数据库获取订单的快递路线;
<div class="row">
<!--Middle Part Start-->
<div id="content" class="col-sm-12">
<h1 class="title">Orders</h1>
<% for(p=0; p<orders.length; p++){ %>
<div class="panel panel-default">
<div class="panel-body">
<ul class="list-group">
<% for(i=0; i<items.length; i++){ %>
<li class="list-group-item">
<span class=''><%= items[i].name %> <%= items[i].qty %> <%= items[i].price %>
<%= items[i].price %></span>
</li>
<% } %>
</ul>
</div>
<div class="panel-footer"> </div>
</div>
<% } %>
</div>
});
最后是ejs模板;
x
通过个人订单循环让我很头疼。
答案 0 :(得分:0)
经过更多的研究,这解决了我的问题:
<div class="row">
<!--Middle Part Start-->
<div id="content" class="col-sm-12">
<h1 class="title">Orders</h1>
<% for(i=0; i<orders.length; i++){ %>
<div class="panel panel-default">
<div class="panel-body">
<ul class="list-group">
<% for (p in orders[i].cart) { %>
<li class="list-group-item">
<span class=''><%= orders[i].cart[p].item.name %> quantity:<%= orders[i].cart[p].qty %> Unit Price:<%= orders[i].cart[p].item.price %>
Total Price :<%= orders[i].cart[p].price %></span>
</li>
<% } %>
</ul>
</div>
<div class="panel-footer">
<a><span>Status : <span><%= orders[i].status %> </div>
</div>
<% } %>
</div>
<!--Middle Part End -->
</div>