jQuery模板-在模板中执行JS代码 [英] jQuery Template - Executing JS code inside the template

查看:90
本文介绍了jQuery模板-在模板中执行JS代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图学习有关jQuery模板的更多信息,但似乎无法在模板内执行任何JS调用.

I am trying to learn more about jQuery templates but cant seem to execute any JS calls inside the template.

<script id="log-item" type="text/x-jquery-tmpl">
 {{if title.length }}
   <h3 style="padding-bottom:5px;">${ title }</h3>
 {{/if}}
 objectToString(${ detail });
</script>

请注意,从未调用过我的objectToString()函数,只是将其渲染为字符串.我试过将它用{{}}包裹起来,但是一时没走.有人可以帮忙吗?

Note that my objectToString() function is never called, just rendered out as a string. I tried wrapping it in {{ }} on a whim but no luck. Anyone out there who can help?

推荐答案

安东尼,可以.您的调用方法需要在模板标记中,如下所示:

Anthony, you can. The method your calling needs to be inside a template tag like so:

<script id="log-item" type="text/x-jquery-tmpl">
 {{if title.length }}
   <h3 style="padding-bottom:5px;">${ title }</h3>
 {{/if}}
 <p>
    Detail: ${ objectToString( detail ) }
 </p>
</script>

这篇关于jQuery模板-在模板中执行JS代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆