[英]Can I assign to a jade variable from inside javascript?
I've seen tons of questions the other way around, but can't find one for assigning to.我已经看到了很多相反的问题,但找不到一个可以分配给。
So, why can I do this:那么,为什么我可以这样做:
var username = '#{username}';
But not this?但不是这个?
#{username} = username;
Is there a way to assign to jade variables from inside javascript?有没有办法从javascript内部分配给玉变量?
Edit: I ended up doing what Bigood suggested and using server and client side cookies, that works great!编辑:我最终按照 Bigood 的建议进行了操作,并使用了服务器端和客户端 cookie,效果很好! I followed a guide that I found from here https://stormpath.com/blog/everything-you-ever-wanted-to-know-about-node-dot-js-sessions/
我遵循了从这里找到的指南https://stormpath.com/blog/everything-you-ever-wanted-to-know-about-node-dot-js-sessions/
When you do #{username} = username
inside Jade, The #{username}
get replaced with the value of username.当您在 Jade 中执行
#{username} = username
, #{username}
将替换为 username 的值。
for example, lets say you are passing username='Jake'
to your jade template.例如,假设您将
username='Jake'
传递给您的 jade 模板。 so when you write所以当你写
#{username}= "somethingElse"
It actually becomes它实际上变成
<Jake> = "somethingElse"</Jake>
Thats the reason we cant do that.这就是我们不能这样做的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.