把手& Backbone - 主干html无法正确呈现

时间:2013-04-30 15:43:36

标签: jquery backbone.js handlebars.js

我正在使用骨干而不是下划线的Handlebars。我确实遇到了渲染模板不附加到我指定的实际元素的问题。

型号:

ImageApp.Models.Image = Backbone.Model.extend({
defaults: {
    imagePath: '',
    description: 'No description available',
    postedOn: ''
    }
});

查看:

 ImageApp.Views.ImageView = Backbone.View.extend({
 tagName: 'ul',

 initialize: function() {
     this.render();  
 },

 render: function() {
     var compiledTemplate = Handlebars.compile($('#imageList-template').html());
     var renderedTemplate = compiledTemplate(this.model.toJSON());

     this.$el.html(renderedTemplate);

    $('#imageList').html(this.el);
 }
});

模板

<script id="imageList-template" type="text/x-handlebars-template">
    <li>
        <img src='{{imagePath}}' title='{{description}} />
    </li>
</script>

我希望这会产生一个无序列表,其中包含一个包含img元素的项目,但是它创建的所有内容都是一个空列表项。任何人都看到任何明显我做错了吗?

1 个答案:

答案 0 :(得分:2)

您错过了{{description}}之后可能会破坏模板的结束单引号。

已移至按要求回答 (我没有能力将评论移到问题上)