I am trying to model a chessboard in Backbone.js. My idea was to create an 8x8 nested array of models that are assigned views. A simplified version of the code is like this:
Inside 'main.js':
new App.View.Board({
model: App.Model.Board()
});
And then inside '/model/Board.js':
App.Model.Board = Backbone.Model.extend({
initialize: function() {
this.squares = new App.Collection.Squares(
_.flatten(
_.map(_.range(1, 9), function(y) {
return _.map(_.range(1, 9), function(x) {
return new App.Model.Square({
x: x,
y: y,
view: new App.View.Square()
});
});
})
)
);
}
...
Anyway, I never know whether a model is assigned to a view or a view is assigned to a model. It seems like a slippery slope. Do models get views or do views get models?
Views get Models. When you create a View you can pass it the Model that it will use. On the other hand, a Model does not take a View.