handlebars.js 刚刚停止工作?
我有一个有趣的问题。我有一个handlebars.js 模板,它已经工作了一个星期,然后就停止了。我希望有人能知道为什么。
这是模板
<script id="banners-template" type="text/x-handlebars-template">
<div class="banner-container" >
{{#banners}}
<ul class="banner" >
<li><div class="checkbox"></div></li>
<li>{{publisher_status}}</li>
<li><a href="{{url}}">Test Link</a></li>
<li><img class="banner" src="{{imageurl}}"/></li>
<li>{{description}}</li>
<li>{{width}}x{{height}}</li>
</ul>
{{/banners}}
</div>
</script>
这是与此一起使用的代码。
var bannersRawTemplate = $("#banners-template").html();
var bannersTemplate = Handlebars.compile(bannersRawTemplate);
data = '{"banners":[{"type":"banner","width":125}]}';
alert(bannersTemplate(data));
我意识到上面的模板中没有访问类型,但这应该不重要。我仍然应该让“横幅”数组循环内的代码显示一次。事实并非如此。模板中显示的唯一部分是 。就像在 JSON 中看不到横幅数组一样。
有什么想法吗?
提前致谢。
I have an interesting problem. Ive had a handlebars.js template thats been working for a week and just stopped. I was hoping someone might have an idea as to why.
Heres the template
<script id="banners-template" type="text/x-handlebars-template">
<div class="banner-container" >
{{#banners}}
<ul class="banner" >
<li><div class="checkbox"></div></li>
<li>{{publisher_status}}</li>
<li><a href="{{url}}">Test Link</a></li>
<li><img class="banner" src="{{imageurl}}"/></li>
<li>{{description}}</li>
<li>{{width}}x{{height}}</li>
</ul>
{{/banners}}
</div>
</script>
Heres the code that works with this.
var bannersRawTemplate = $("#banners-template").html();
var bannersTemplate = Handlebars.compile(bannersRawTemplate);
data = '{"banners":[{"type":"banner","width":125}]}';
alert(bannersTemplate(data));
I realize that type is not accessed in the template above but it shouldnt matter. I should still get the code inside of the "banners" array loop displayed once. This is not the case. The only part of the template that displays is . Its like its not seeing the banners array inside the JSON.
Any ideas?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不传递实际 JSON 而是传递字符串是否有特殊原因?根据我使用 Mustache 的经验,以及对 Handlebars.js 文档的粗略回顾,您应该通过:
并且,假设您显示的代码是“真正真实的”,为什么不只是:
当然,这是假设问题实际上不是您有一个只有一个元素的列表。
Is there a particular reason you don't pass in the actual JSON, and instead pass a string? From my experience with Mustache, and a cursory review of the Handlebars.js documentation, you should be passing:
And, assuming the code you've shown is "really real", why not just:
This is, of course, assuming that the issue really isn't that you've got a list with just one element.