Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should views keep track of their model?

Tags:

backbone.js

This nice article recommends against keeping track of the views belonging to a model inside the model. What about the opposite? It is recommended for views to keep track of the model(s) they are based on?

It seems difficult to imagine to do without. Maybe the recommended way is to use events, or something?

like image 817
Randomblue Avatar asked Jan 23 '26 23:01

Randomblue


1 Answers

Views always keep a reference to the model. It is accessible through myView.model or myView.collection.models.

Due to the nature of views, I cannot imagine a case where you would want the view to not know about the model. Event binding happens in the view with a reference to a model. (Think about the collection.add event. Wouldn't be possible if you didn't bind to a reference to the collection)

like image 140
Chris Biscardi Avatar answered Jan 25 '26 15:01

Chris Biscardi