find查询的数据,我想在任何一个ejs模板中都可以使用他的数据 ,如何做一个公共的,可以全局访问的数据(在ejs模板中)?
发布于 6 年前 作者 wiscgazf 1862 次浏览 来自 问答

Notes.find().populate({ path: ‘author’, select: ‘name’, model: ‘admin’ }).limit(10).sort({createTime: -1}).exec(function (err, data) { if (err) { res.status(500).json(Errors.networkError); } else { res.render(‘pc/index’, { Datas: data.map(item => { return { id: item._id, createTime: moment(item.createTime).format(“YYYY-MM-DD”), title: item.title, thumbImg: item.thumbImg, pageView: item.pageView, category: item.category, description: item.description, author: item.author, replyData: item.replyData.length } }) }) } }) };

此时数据只能在当前返回的ejs页面中获取到,有什么办法可以在其他ejs模板中也可以使用这个数据 ,不用其他页面也查询一遍在返回 同样的数据

回到顶部