这是我的路由文件,我正在尝试渲染shopping.hbs文件。 我在console.log.Shopping-cart.hbs文件中获得了正确的输出,在我的商店文件夹里面查看。
ffmpeg -loop 1 -i pic001.jpg -i pic002.jpg -filter_complex "[0:v]scale=-1:720,zoompan=z='min(zoom+0.0015,1.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=125,trim=duration=5[scaled_video];[1:v]scale=1920:1080,boxblur=15[blur_image];[blur_image][scaled_video]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2[outv]" -c:v libx264 -aspect 1280/720 -map [outv] -t 10 -y fixed.mp4
以下是generateArray的代码。如果我将数组传递到页面中,则页面呈现成功。
router.get('/shopping-cart',function(req,res,next){
if(!req.session.cart)
{
return res.render('shop/shopping-cart',{products:null});
}
var cart=new Cart(req.session.cart);
console.log(cart.totalPrice);
console.log(cart.generateArray());
res.render('shop/shopping-cart',{products:cart.generateArray(),totalPrice: cart.totalPrice});
});
module.exports = router;
这是控制台的输出。
module.exports=function Cart(oldCart) {
this.items=oldCart.items || {};
this.totalQty=oldCart.totalQty || 0;
this.totalPrice=oldCart.totalPrice || 0;
this.add=function(item,id)
{
var storedItem=this.items[id];
if(!storedItem)
{
storedItem=this.items[id]={item:item,qty:0,price:0};
}
storedItem.qty++;
storedItem.price=storedItem.qty*storedItem.item.price;
this.totalQty++;
this.totalPrice+=storedItem.item.price;
};
this.generateArray=function(){
var arr=[];
for(var id in this.items){
arr.push(this.items[id]);
}
return arr;
};
};
这是我的shopping-cart.hbs文件,我正在迭代产品。
6000
[ { item:
{ _id: '5a033713520a9414e9e6e0ac',
imagePath: 'https://media.contentapi.ea.com/content/dam/ea/easports/fifa/features/2017/cristiano-ronaldo/june5/ronaldo-share.jpg',
title: 'FIFA 2018',
description: 'PC Game',
price: 2000,
__v: 0 },
qty: 3,
price: 6000 } ]
以下是句柄栏的配置设置
{{ # if products }}
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<ul class="list-group">
{{ # each products }}
<li class="list-group-item">
<span class="badge">{{this.qty}}</span>
<strong>{{this.item.title}}</strong>
<span class="label label-success">Rs {{this.price}}</span>
<div class="btn-group">
<button class="btn btn-primary btn-xs dropdown-toggle" type="button" datatoggle="dropdown">Action<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Reduce by 1</li>
<li><a href="#">Remove all</li>
</ul>
</div>
</li>
{{ /each }}
</ul>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<strong>Total : {{ totalPrice }}</strong>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<button type="button" class="btn btn-success">Checkout</button>
</div>
</div>
{{ else }}
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<h2>No items in Cart</h2>
</div>
</div>
{{ /if }}