javascript - 如何将信息从控制器传递到局部视图
问题描述
我遇到了快递问题,我不知道如何解决。我希望能够将信息从控制器传递到部分视图(标题)。问题是,当我访问控制器中呈现的视图以外的视图时,它会中断。如何将信息传递给一个视图并使其在所有视图中都起作用。
const indexController = (req, res) => {
let emailSession;
if(req.session.userLogged == undefined){
emailSession = "";
} else {
emailSession = req.session.userLogged.email
}
db.Users.findOne({
where: {email: emailSession}
}).then((data) => {
res.render('index', {data}) //I want here to send the same variable to all of my views that has the same header, not just the index view
)
}
<nav>
<% if(data.info == "something") {%>
<a href="">Dashboard</a>
<% } %>
</nav>
解决方案
推荐阅读
- c# - 当我将 C# 与 mongo 驱动程序一起使用时,有没有办法在 Cosmos db 中以 ISO 格式存储日期时间变量
- python - 根据每个分数对预测池中的样本进行排名
- c++ - 有没有办法以特定方式显示 cpp 图
- javascript - 在 vb.net 中使用 Ajax 时找不到具有给定 url 的资源错误
- python - 运行带有输入/输出参数的 bash 命令,但将它们作为不在磁盘中的变量提供
- windows - 无法在 Vim 上制作 Dracula 主题 [os: W10]
- c# - .NET Core 从无法返回重定向的方法将用户发送到页面
- sql-server - 了解具有高安全模式和手动故障转移的数据库镜像会话设置。为什么会有人选择这种组合?
- google-cloud-platform - googleapi: 错误 400: Precondition check failed., failedPrecondition while create Cloud Composer Environment through Terraform
- c# - 如何将 FirestoreProperty 与 DocumentReference 结合使用?