i'm stuck trying info "product" , "channel" mongo object. have "cannot read property 'length' of undefined" while looping through nested array of objects:
{ "_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" }] }
jade query:
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}
output:
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
and node code:
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 }) }
at level "country" works fine - country displayed properly. item "item.elems" alone shows array of objects: [object object],[object object],[object object].
Comments
Post a Comment