Backbone.js 视图主干中的传递模型
嗨,我的路由器中有这个功能:Backbone.js 视图主干中的传递模型,backbone.js,Backbone.js,嗨,我的路由器中有这个功能: home: function() { var attore= new Attore(); var page = new ListPostView({ model: this.attore }); this.changePage(page); }, 阿托尔的模型是: var Attore = Backbone.Model.extend({ defaults: { "nome": "caesar salad", "cognome": "r
home: function() {
var attore= new Attore();
var page = new ListPostView({
model: this.attore
});
this.changePage(page);
},
阿托尔的模型是:
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;
});
可能是因为您试图传递
此.attore
,但您从未将您的型号分配给路由器。您可能打算直接传入模型var page=newlistpostview({model:attore})这个错误很奇怪,有什么奇怪的?你从哪里得到的错误?您是否尝试过像我在上一篇评论中建议的那样更改行?是的,我尝试过您建议的代码看起来您试图将ListPostView中的模型视为一个集合。。。