嗨,我在路由器中有这个功能:
home: function() {
var attore= new Attore();
var page = new ListPostView({
model: this.attore
});
this.changePage(page);
},
和模型Attore是:
var Attore = Backbone.Model.extend({
defaults: {
"nome": "caesar salad",
"cognome": "ravioli"
},
});
return Attore;
});
但是发生了一个错误,告诉我模型在视图中未定义:
var ListPostView = Backbone.View.extend({
tagName: "ul",
id: "list",
template: Handlebars.compile(template),
initialize: function () {
console.log(attore);
this.model.bind("reset", this.render, this);
},
render: function (eventName) {
$(this.el).empty();
_.each(this.model.models, function (ad) {
$(this.el).append(new SinglePostView({
model: ad
}).render().el);
}, this);
return this;
}
});
return ListPostView;
});