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

后端 未结 2 1339
青春惊慌失措
青春惊慌失措 2020-12-30 04:50

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 =          


        
相关标签:
2条回答
  • 2020-12-30 05:18

    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 :-)

    0 讨论(0)
  • 2020-12-30 05:31

    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/

    0 讨论(0)
提交回复
热议问题