开发者

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>

Grails interferes with jquery-tmpl syntax

RIGHT

<tr id="ad{{= idmatchingtem }}"></tr>

Grails interferes with jquery-tmpl syntax

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜