来自mongoDb的数据未显示在把手上

时间:2017-11-24 06:51:38

标签: node.js mongodb handlebars.js

我正在尝试显示来自mongoDb的一些数据,但它没有显示在Handlebars上。但是当我记录它然后它显示正确..

获取方法代码:

router.get('/', function(req, res){
db.collection('Product').find().toArray((err, result) => {
    if (err) return console.log(err)
    res.render('shop/index', {  title: 'Shoping Cart', products: 
result});
    console.log(result);
  })
})

把手代码:

{{# each products }}
<div class="row">
    {{# each this}}
    <div class="col-sm-3 col-md-3">
    <div class="thumbnail">
        <img src="{{ this.imagePath }}" alt="..." class="img-responsive" style="max-heigenter code hereht: 150px">
       <div class="caption">
       <h3>{{ this.title }}</h3>
       <p><{{ this.description }}</p>
       <div class="clearfix">
       <div class="price pull-left">${{ this.price }}</div>
      <a href="#" class="btn btn-success pull-right" role="button">Button</a>
   </div>
   </div>
   </div>
   </div>
   {{/each}}
</div>
{{/each}}

日志之后Arry正在显示:

[ { _id: 5a16f0e0480b08283a5d0373,
    imagePath: 'https://upload.wikimedia.org/wikipedia/en/5/5e/Gothiccover.png',
    title: 'Gothic Video Game',
    description: 'Awsome Game!!!',
    price: '10' },
  { _id: 5a16f8dfd4c0bf2c1e490e46,
    imagePath: 'https://upload.wikimedia.org/wikipedia/en/thumb/d/d2/Need_for_Speed_Undercover_cover.jpg/256px-Need_for_Speed_Undercover_cover.jpg',
    title: 'Need For Speed',
    description: 'This is Awsome racing Game!!!',
    price: '20' },
  { _id: 5a16f90dd4c0bf2c1e490e47,
    imagePath: 'https://media.newyorker.com/photos/590977c9019dfc3494ea2f7f/master/w_649,c_limit/Johnston-Clash-Clans.jpg',
    title: 'Clash Of Clans',
    description: 'Most Popular Online Game Ever!!!',
    price: '55' },
  { _id: 5a17a7baf326291813be29fe,
    imagePath: '',
    title: '',
    description: '',
    price: '' } ]

0 个答案:

没有答案