开发者

JQuery Templates: pass parameter into a function

开发者 https://www.devze.com 2023-03-06 19:20 出处:网络
So I have this JQuery template that calls a function: <script id=\"Fred\" type=\"text/x-jQuery-tmpl\">

So I have this JQuery template that calls a function:

<script id="Fred" type="text/x-jQuery-tmpl">
  <td>${functionX()}${Field2}</td>
</script>

Works great. but now I want to pass a parameter into it, but the following won't work.

<script id="Fred" type="text/x-jQuery-tmpl">
  <td>${functionX(${Field1})}${Field2}</td>
</script&g开发者_Go百科t;

Any suggestions?


You can access Field1 directly without using ${, like:

<td>${functionX(Field1)}${Field2}</td>


figured it out:

<td>${functionX($data.Field1)}${Field2}</td>


This is another example of how the problem could be solved:

<script id="testTemplate" type="text/x-jquery-tmpl">
    {{if title.length}}
    <h3>${title}</h3>
    <p>Start: ${ render($data) } :End</p>
    {{/if}}
</script>

You can see that this method works in this link.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号