【发布时间】:2014-06-12 19:16:03
【问题描述】:
当实例化一个新视图时,我传入了一个模型。我可以在“初始化”属性中访问该模型,但是当我尝试将模型传递到模板时无法引用它。知道为什么吗?
var postView = Backbone.View.extend({
initialize : function() {
// returns model
console.log('the model we are interested in',this.model);
this.render();
},
el : "#blog-post",
template : function() {
// returns undefined
var model = this.model;
return _.template($('#postview').html(), {
post : model
});
},
render : function() {
var self = this;
this.$el.html(self.template);
}
});
我正在使用另一个视图中的方法对其进行实例化:
readMore : function(e, index) {
var self = this;
var newView = new postView({
model : self.collection.models[index].toJSON()
});
}
【问题讨论】: