[英]Can I declare local/temp variables within a jQuery template?
Is it possible to declare new variables within the jQuery template syntax? 是否可以在jQuery模板语法中声明新变量? I'm hoping to achieve the equivalent of this (which does not work):
我希望达到相当于这个(这不起作用):
{{var test = "test"}}
<div>
${test}
</div>
I know this has already been answered and accepted, but here is another solution: 我知道这已经得到了回答和接受,但这是另一种解决方案:
${( $data.localVariable = 'SOMETHING' ),''}
A jsFiddle example: http://jsfiddle.net/brettwp/PrfZ5/ 一个jsFiddle示例: http : //jsfiddle.net/brettwp/PrfZ5/
This is pretty lame, but one trick that might work is: 这非常蹩脚,但可能有用的一个技巧是:
{{each(i, test) ["test"]}}
blah blah ${test} blah
{{/each}}
I'm not 100% sure however about using an array constant expression like that; 我不是100%肯定使用像这样的数组常量表达式; I'll set up a fiddle.
我会设置一个小提琴。 ( edit yes it works :-)
( 编辑是的它有效:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.