简体   繁体   English

如何在玉器中使用多个数组

[英]how to use multiple arrays in jade

I have items in mongo database as the following: 我在mongo数据库中有以下项目:

"_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" 我正在使用Node.js express和jade输出“类别”和“类型”

I have a find method in index.js to find all the documents in a collection. 我在index.js中有一个find方法来查找集合中的所有文档。

/* 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM