如何从API(express js)将数据显示到ejs
使用Express JS,我想渲染由我的EJS文件产生的JSON。
这是我的控制器生产JSON,
const getAllQuotes = asyncWrapper(async (req, res) => {
const quotes = await qSchema.find({});
res.status(200).json({ quotes });
});
我想将JSON从控制器传递到下面的路由器,然后我的路由器的作用是带上数据并将数据显示到管理页面
adminRoute.get('/', async (req, res) => {
//what should i type here?
res.render("admin")
})
,或者我的问题是关于如何抛出/传递数据的问题在JS文件之间
Using express js, i want to render json that has been produced by my to ejs file.
here is my controller that produce json
const getAllQuotes = asyncWrapper(async (req, res) => {
const quotes = await qSchema.find({});
res.status(200).json({ quotes });
});
I want to pass the JSON from controller to my router below, then what my router does is bring the data and show the data to admin page
adminRoute.get('/', async (req, res) => {
//what should i type here?
res.render("admin")
})
or maybe my question is about how the data can be thrown/passed in between js file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要从您的服务器向您的服务器发出 HTTP 请求。
您有一个获取数据的函数。使用该功能。
Don't make HTTP requests from your server back to your server.
You have a function that gets your data. Use that function.