Reputation: 24949
I am using express.js with jade. I have a problem in jade template.
my mogodb data is like following
{ _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 },
from my jade template
- 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}
How can I use first array of pic array
?
I checked on doc, https://github.com/visionmedia/jade , it didn't include about array. They only show with Iteration and array.
If there is no pic, I want to show other pic instead.
Is there possible done in Jade template or I need to do at js side ?
Upvotes: 0
Views: 5878
Reputation: 24949
- 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)
Thank @Ray Toal
Upvotes: 3