admin管理员组文章数量:1389231
Hi I have been trying to use backbonejs and handlebar templates but seems like either my jSON is wrong or data is not properly parse . Getting
Uncaught Error: You must pass a string to Handlebarspile. You passed undefined
Code can be found at
jsfiddle
any advice will be appreciated
Hi I have been trying to use backbonejs and handlebar templates but seems like either my jSON is wrong or data is not properly parse . Getting
Uncaught Error: You must pass a string to Handlebars.pile. You passed undefined
Code can be found at
jsfiddle
any advice will be appreciated
Share Improve this question asked Nov 7, 2013 at 19:34 PaulPaul 791 gold badge3 silver badges12 bronze badges 1-
Looks like you're missing a "#" in your template each statement; it should be
{{#each propertiesABC}}
– VLS Commented Nov 7, 2013 at 19:57
1 Answer
Reset to default 6Your fiddle is broken in various ways but the odds are that you're doing this:
template: Handlebars.pile($('#tpl-page-list-item').html()),
before there is a #tpl-page-list-item
available. This will happen if your page looks like:
<script src="your_backbone_javascript.js"></script>
<script id="tpl-page-list-item" ...></script>
as your Backbone view will be parsed before <script id="tpl-page-list-item">
gets added to the DOM. You can wrap your Backbone views in a document-ready handler (with proper namespacing to account for the function wrapper):
$(function() {
window.PageListItemView = Backbone.View.extend({
template: Handlebars.pile($('#tpl-page-list-item').html()),
//...
});
});
or pile the template when instantiating your view:
initialize: function() {
// Or check if it is in the prototype and put the piled template
// in the prototype if you're using the view multiple times...
this.template = Handlebars.pile($('#tpl-page-list-item').html());
//...
}
本文标签: javascripthandlebar compilation errorsStack Overflow
版权声明:本文标题:javascript - handlebar compilation errors - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744631175a2616548.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论