Grails interferes with jquery-tmpl syntax
The jQuery templates plug-in uses ${foo}
syntax (example in jquery.tmpl doc):
$.tmpl( "<li>${Name}</li>", myData )
But Grails also uses it (example in Grails doc):
<body>
Hello ${params.name}
</body>
So when I include $.tmpl( "<li>${Name}</li>", myData )
in my .gsp, Grails renders it as $.tmpl( "<li></li>", myData );
.
Is there an easy way around this?
use the alt syntax: {{= Name }}
http://api.jquery.com/template-tag-equal/
I have only dabbled in Grails, but one option to get the literal output:
$.tmpl("<li><%='${Name}'%></li>", myData)
You may try using jquery.noConflict or jQuery itself:
jQuery.tmpl( "<li>${Name}</li>", myData )
or
var jqc = jQuery.noConflict();
jqc.tmpl( "<li>${Name}</li>", myData )
To avoid conflict , you should use the syntax mentioned by zack. However,Be careful when you use this tag :
{{= Name}}
you should have space between "=" and the first letter of variable.
{{=Name}}
{{= Name}}
EXAMPLE:
WRONG
<tr id="ad{{=idmatchingtem }}"></tr>
RIGHT
<tr id="ad{{= idmatchingtem }}"></tr>
精彩评论