最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - handlebar compilation errors - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 6

Your 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());
    //...
}
发布评论

评论列表(0)

  1. 暂无评论