我有一些预订的输出,必须以几种方式使用。
我将基于时间戳格式的“ dateto”字段,使用它来显示当前预订列表以及过去的预订列表
我只想使用已经拥有的数据,而不是进行多个查询(WHERE dateto <currentdate,WHERE dateto> currentdate等),但是我有点不确定如何解决这个问题。
我有这个代码。
let list = (req, res, next) => {
fetchAll(req.params.hid).then((bookings) => {
if (bookings.length > 0) {
(async () => {
res.render('profile/bookings/bookings.ejs', {
bookings: bookings,
moment: moment,
totalDays: await countBookingDays(bookings)
})
})()
} else {
res.send('No result')
}
}).catch((error) => {
res.status(500).send(error)
})
}
countBookingDays()
只是一个功能,可以汇总今年至今的所有预订天数-对于此特定问题并不重要。
我想以bookings
某种方式将其映射为以dateto <currentdate创建新数组(pastBookings)
所以在我的EJS文件中,我可以将其与类似的东西一起使用
res.render('profile/bookings/bookings.ejs', {
currentBookings: bookingsMappedToCurrent,
pastBookings: bookingsMappedToPast
moment: moment,
totalDays: await countBookingDays(bookings)
})
人!事情太复杂了很容易
let currentBookings = bookings.filter(booking => booking.b_dateto > timeNow)
let pastBookings = bookings.filter(booking => booking.b_dateto < timeNow)
完美的作品!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句