I have items in mongo database as the following:
"_id":01, "category": "Electronics", "type": "Television", price:345.00
"_id":02, "category": "Electronics", "type": "Mobile", price:145.00
"_id":03, "category": "Electronics", "type": "ipad", price:300.00
I am using Node.js express and jade to output the "category" and "type"
I have a find method in index.js to find all the documents in a collection.
/* GET Electronics page. */
router.get('/electronics', function(req, res) {
var db = req.db;
var collection = db.get('website');
collection.find({},{},function(e,docs){
res.render('electronics', {
"electronics" : docs
});
});
});
I am able to print "type" field for all the documents first and then "price" field for all the documents using jade
for type in electronics
a(href="/beauty")=type.type
for price in electronics
a(href="/beauty")=price.price
output of the above code is something like:
Television
Mobile
ipad
345.00
145.00
300.00
I want to print for every "type" it should print its corresponding "type". something like
Television 345.00
mobile 145.00
ipad 300.00
Can anyone please help me
You should do something like this:
for item in electronics
a(href="/beauty")=item.type
a(href="/beauty")=item.price
br
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.