dears am new at mongodb and express and trying to make a simple website let say home page and about , contact , albums, blogs. so i made a collections for the above and now my issue is in home page which it will contain slider, welcome paragraph, 3 images from albums, and 3 blogs from blogs so my code was like below but i feel it is wrong can you help me please to render more than one collection in same page but in best practis way .
my code like
var Slider = require('../models/slider');
var About = require('../models/about');
var Hours = require('../models/hours');
/* GET home page. */
router.get('/', function(req, res, next) {
Slider.find(function(err, sliderimages) {
About.find(function(err, homeabout){
Hours.find(function(err, workinghours) {`enter code here`
var openinghours ='';
for(var i=0 ;i < workinghours.length ; i++){
openinghours = workinghours[i];
openinghours.Sat.startHour == 'Closed' ? openinghours.Sat.startHour = null : '';
openinghours.Sun.startHour == 'Closed' ? openinghours.Sun.startHour = null : '';
openinghours.Mon.startHour == 'Closed' ? openinghours.Mon.startHour = null : '';
openinghours.Tus.startHour == 'Closed' ? openinghours.Tus.startHour = null : '';
openinghours.Wed.startHour == 'Closed' ? openinghours.Wed.startHour = null : '';
openinghours.Thu.startHour == 'Closed' ? openinghours.Thu.startHour = null : '';
openinghours.Fri.startHour == 'Closed' ? openinghours.Fri.startHour = null : '';
openinghours.Sat.startHour == 'Closed' ? openinghours.Sat.startHour = null : '';
}
res.render('index', { title: 'Express',sliderimages:sliderimages , homeabout: homeabout, openinghours: openinghours});
});
});
});
});
via Ali Al Roomi
No comments:
Post a Comment