Express + NodeJs框架中的Jade Object迭代

时间:2015-01-17 21:46:40

标签: node.js mongodb express pug

我正在使用带有Express框架和MongoDB的Node.js。在我的index.js文件中,我有这样的路线。

router.get('/adslist', function(req, res) {
var db = req.db;
var collection = db.collection('adscollection');
collection.find({},function(e,docs) {
  docs.each(function (err, docc) {
      if (docc) {
        console.log(docc);
      }
    });
  res.render('adslistpage', {userlist: docs});
  });
});

我能够像这样在控制台中看到输出

{ "_id":"...", "adid": "1"}

但是我无法在Jade中迭代对象。

extends layout
block content
h1.
  User List
p=userlist
ul
  each user, i in userlist
     li #{user.adid}

虽然'p=userlist'正在打印[object Object]但我在'ul'

中收到错误
Cannot read property 'adid' of undefined

0 个答案:

没有答案