为什么我无法从Jade中的mongodb获取嵌套数据?

时间:2016-08-01 13:55:47

标签: json node.js mongodb pug

我试图了解"产品"和"频道"来自我的mongo对象。但是"无法读取属性'长度'在循环嵌套的对象数组时,未定义"

{
    "_id": ObjectId("579f14f0661cf39cc86c75be"),
    "category": "slim"
        {
            "_id": ObjectId("579f14f0661cf39cc86c75bf"),
            "country": "AT",
            "elems": [{
                "chanell": "ATD",
                "produkt": "prod A"
            }, {
                "chanell": "RTB",
                "produkt": "prod B"
            }, {
                "chanell": "SEO",
                "produkt": "prod C"
            }]
        } {
            "_id": ObjectId("579f14f0661cf39cc86c75c0"),
            "country": "DE",
            "elems": [{
                "chanell": "ATD",
                "produkt": "prod A"
            }, {
                "chanell": "RTB",
                "produkt": "prod B"
            }, {
                "chanell": "SEO",
                "produkt": "prod C"
            }]
        } 

玉查询:

block content
  h3.
    Products
  div
    p First Pargraph
      - each item in productlist
        p Country: #{item.country}
          - each elem in item.elems
            p #{elem.channell}
            p #{elem.produkt}

输出:

TypeError: /var/www/html/projects/bartek/ang/produkty/public/views/productlist.jade:10
   8|       - each item in productlist 
   9|         p Country: #{item.country} 
 > 10|           - each elem in item.elems 
   11|             p #{elem.channell} 
   12|             p #{elem.produkt}

Cannot read property 'length' of undefined

我的节点代码:

var collection = db.collection('slim');

        collection.find({}).toArray(function(err,result){
            if (err) {
                res.send(err);
            } else if (result.length) {
                res.render('productlist',{
                 'productlist' : result   
                })
            }

等级#34;国家"一切正常 - 国家显示正常。项目" item.elems"单独显示对象数组:[object Object],[object Object],[object Object]。

0 个答案:

没有答案