简体   繁体   English

如何从玉文件中的javascript文件访问变量的值?

[英]How to access the value of a variable from a javascript file in a jade file?

I have created a variable in my js file called loginCount. 我在我的js文件中创建了一个名为loginCount的变量。

This is how I have defined it: 这是我的定义方式:

var loginCount = 0; 

and this is how I am using it in this file: 这就是我在此文件中使用它的方式:

function login(req, res) {
    var username = req.body.username;
    req.session.username = username;
    loggedInUsers[username] = LoggedIn;
    req.session.loginCount = loginCount;
    for (username in loggedInUsers){ 
        loginCount++;
        console.log("Login Count:", loginCount);
    }
    res.redirect("/users")
}

In my jade file I have tried 在我的翡翠档案中,我尝试过

(#{loginCount} sessions)

but this doesn't work, it only shows ( sessions). 但这不起作用,仅显示(个会话)。 Any insight? 有见识吗?

Thanks! 谢谢!

in calling the jade file try:- 在调用玉文件时,请尝试:

res.redirect("/users", {login: loginCount } );

now you can refer to the variable in jade :- 现在您可以在jade中引用变量:

#{loginCount} // this will type the value of the variable.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM