...">

JQuery templates: pass parameter to function

So, I have this jQuery template that calls a function:

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

It works great. but now I want to pass a parameter to it, but the following will not work.

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

Any suggestions?

+4
source share
3 answers

You can directly access Field1 without using $ {, for example:

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

figured it out:

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

This is another example of how a problem can 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 .

-1
source

All Articles