[英]pass ALL local variables from Jade to JavaScript
I can find solutions to pass local variables from jade to javascript, for example: 我可以找到将局部变量从jade传递到javascript的解决方案,例如:
script.
var myVar = `#{myVar}`;
script(src=src)
But since I want to use my jade template for many views, with different sets of variables, I wonder if it is possible to pass ALL available local variables. 但是由于我想将我的Jade模板用于具有不同变量集的许多视图,因此我想知道是否可以传递所有可用的局部变量。
Going off the answers to this question it doesn't look like there's a clean way of getting all variables in scope. 离开这个问题的答案,似乎没有一种干净的方法可以将所有变量都包含在范围内。
In which case you're best off gathering all variables you want to pass to your jade/pug in a single object and then pass that object to the pug file. 在这种情况下,最好将所有要传递给玉/ pug的变量收集到一个对象中,然后将该对象传递给pug文件。
const holder = {};
holder.one = 1;
holder.two = 2;
pug.compile(page, holder);
You can then do 然后你可以做
script.
var one= `#{one}`;
script(src=src)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.