我有一个包含CellModels的CellCollection的BoardView。我从数据库中获取了集合,然后创建了CellViews。
这一切都很顺利,直到我尝试通过在BoardView上点击事件访问CellModel。我根本无法访问底层模型...只有视图。有没有办法做到这一点?
我已经尝试包含下面相关的代码:
CellModel = Backbone.Model.extend({});
CellCollection = Backbone.Collection.extend({
model : CellModel
});
CellView = Backbone.View.extend({
className : 'cell',
});
BoardView = Backbone.View.extend({
this.model.cells = new CellCollection();
render : function() {
this.cellList = this.$('.cells');
return this;
},
allCells : function(cells) {
this.cellList.html('');
this.model.cells.each(this.addCell);
return this;
},
addCell : function(cell) {
var view = new Views.CellView({
model : cell
}).render();
this.cellList.append(view.el);
},
events : {
'click .cell' : 'analyzeCellClick',
},
analyzeCellClick : function(e) {
// ?????????
}
});
我需要在BoardView上进行“点击”,而不是CellView,因为它涉及特定于面板的逻辑。