我使用Underscore.js的Backbones模板有问题。 我将所有模板都放在单独的变量中,并且当我将它们传递给我的模型时,我会开始使用#34; Uncaught TypeError:无法读取属性' html'未定义"
这是我的代码,
var YetiBoxView = Backbone.View.extend({
tagName: 'li',
template_online : yetibox_status_online,
template_offline : yetibox_status_offline,
template_inactive : yetibox_status_inactive,
initialize: function(){
this.render();
},
render: function(){
if( this.model.toJSON().status == "ONLINE") {
this.$el.html(this.template_online(this.model.toJSON()));
} else if (this.model.toJSON().status == "OFFLINE"){
this.$el.html(this.template_offline(this.model.toJSON()));
} else if(this.model.toJSON().status == "INACTIVE"){
console.log(this.model.toJSON());
this.$el.html(this.template_inactive(this.model.toJSON()));
}}
});
var YetiBoxCollectionView = Backbone.View.extend({
el : '#status_list',
render: function(){
this.collection.each(function(yetibox){
var yetibox_view = new YetiBoxView({model: yetibox});
this.$el.append(yetibox_view.el);
}, this);
}
});