Can I declare local/temp variables within a jQuery template?

梦想与她 提交于 2019-11-29 12:13:26

问题


Is it possible to declare new variables within the jQuery template syntax? I'm hoping to achieve the equivalent of this (which does not work):

{{var test = "test"}}

<div>
    ${test}
</div>

回答1:


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; I'll set up a fiddle. (edit yes it works :-)




回答2:


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/



来源:https://stackoverflow.com/questions/5147766/can-i-declare-local-temp-variables-within-a-jquery-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!