jQuery 模板可以绑定到原始数组吗
鉴于
<div id="place_holder" />
<script id="template" type="text/x-jquery-tmpl">
WHAT DO I PUT HERE
</script>
var array_of_ints = [1,2,3]
$( "#template" )
.tmpl( array_of_ints )
.appendTo( "#place_holder" );
我可以在模板中放入什么来获得?
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
Given
<div id="place_holder" />
<script id="template" type="text/x-jquery-tmpl">
WHAT DO I PUT HERE
</script>
var array_of_ints = [1,2,3]
$( "#template" )
.tmpl( array_of_ints )
.appendTo( "#place_holder" );
What can I put within the template to get ?
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
{{= $data}} 在任何地方都适用( ${} 在模板中的字符串中不起作用)
{{= $data}} works everywhere ( ${} wont work in strings in the template )
${} 不适用于字符串数组 ['A String','Another String','Yet Another String'] ,但 {{= $data}} 可以。谢谢!
${} didn't work for me with an array of strings ['A String','Another String','Yet Another String'] , but {{= $data}} does. thanks!
您想要查看
{{each}}
模板标签。在这种情况下,我认为 jQuery.tmpl 并不是真正做到这一点的最佳方法。在我看来,使用标准的
for
循环会容易得多。http://jsfiddle.net/LeKYu/
You want to look into the
{{each}}
template tag.In this case, I don't think that jQuery.tmpl is really the best way to do this. It would be much easier in my opinion just to use a standard
for
loop.http://jsfiddle.net/LeKYu/