2013-04-30 77 views
0

我正在使用Handlebars而不是下划线。我遇到了一个问题,渲染后的模板不会附加到我指定的实际元素上。Handlebars&Backbone - backbone html不能正确呈现

型号:

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); 
} 
}); 

模板

​​

我希望它可以产生一个无序列表包含img元素的单个项目,而是它创建的只是一个空的列表项。任何人看到任何明显的我做错了什么?

+0

2个东西(可能是未成年人)回答 - 1)你不包括模型,所以您可能会在属性中出现拼写错误,2)在{{{description}}之后,您错过了可能会破坏模板的单引号。 – 2013-04-30 15:47:49

+0

@ jesus.tesh大声笑它是单引号...哇...移动它anwser,我会接受它,谢谢! – Justin 2013-04-30 15:51:35

+0

您的示例模型中存在不匹配的{}'。 – loganfsmyth 2013-04-30 16:27:26

回答

2

您错过了{{description}}之后可能会中断模板的单引号。

感动每个请求 (我没有移动到一个问题的意见的能力)