0

我正在将 express.js 与玉一起使用。我的玉模板有问题。

我的 mogodb 数据如下

{ _id: 5040465ce0afabce2b000003,
    address: 'Sample',
    fax: [ '22 212', '34 138' ],
    Branch: true,
    pic: [ 'photo1.png' ,'photo2.png'],
    tel: [ '22 980', '22 439' ],
    lat: 29.674292,
    Name: 'Branch 1',
    ATM: false,
    long: 98.210881 },
{ _id: 5040465ce0afabce2b000003,
    address: 'Loikaw.',
    fax: [  ],
    Branch: true,
    pic: [  ],
    tel: [],
    lat: 20.674292,
    Name: 'Loikaw Branch',
    ATM: false,
    long: 98.210881 },

从我的玉模板

- obj.forEach(function(item){
                tr
                    td 
                        img(src="/upload/#{item.pic}",width=200)
                    td #{item.Name}
                    td #{item.address}
                    td #{item.ATM}
                    td #{item.Branch}
                    td #{item.lat}
                    td #{item.long}

如何使用第一个数组pic array

我检查了文档,https://github.com/visionmedia/jade,它不包括关于数组。它们只显示迭代和数组。

如果没有图片,我想显示其他图片。

有可能在 Jade 模板中完成还是我需要在 js 端完成?

4

1 回答 1

2
- obj.forEach(function(item){
                tr
                    td 
                        - if (item.pic[0] == undefined)
                            img(src="/images/nopic.png",width=200)
                        - else
                            img(src="/upload/#{item.pic[0]}",width=200)

感谢@Ray Toal

于 2012-10-06T04:45:23.610 回答