Javascript 帮助在 Jade Express 中显示变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7160767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
help with displaying a variable in jade express
提问by rabidmachine9
I'm trying to load some variables with res render like that:
我正在尝试使用 res 渲染加载一些变量,如下所示:
res.render('blog_edit', {title: 'edit your blog', posts: "something"});
though title loads fine post always appears as undefined... here are some of the ways I tried...
虽然标题加载好帖子总是显示为未定义......这里是我尝试过的一些方法......
=posts
#{posts}
and as a javascript variable
并作为 javascript 变量
script
document.write(posts)
none of them is working... can you please help? thanks in advance
他们都没有工作......你能帮忙吗?提前致谢
回答by James
try
尝试
res.render('blog_edit', {locals:{title: 'edit your blog', posts: "something"}});
#{locals.foo}
回答by Jesús Carrera
I'm using the latest versions today ("express": "4.11.2", "jade": "1.9.2") and this is the syntax that works for me:
我今天使用的是最新版本(“express”:“4.11.2”,“jade”:“1.9.2”),这是对我有用的语法:
res.render('blog_edit', {title: 'edit your blog', posts: "something"});
In template:
在模板中:
#{locals.posts}
or
或者
#{posts}
回答by Scott Montreuil
Here is what works for me.
这对我有用。
in JS
res.render('index', {email: req.params.email});
in Jade
#{locals.email}