Backbone.js Model to View Connection

It’s not implicit at all, it’s explicit in this line right here:

var view = new TodoView({model: todo});

This is creating a new TodoView view and setting its model property to the addOne function’s only parameter (todo, which is a model).

Whenever a new model is added to the Todos collection, the addOne method is called with the new model as the parameter.

Todos.bind('add', this.addOne);

Then, in addOne, a new view is created for that model and the relationship is explicity set, via {model: todo}. This is what you’re missing from your version of the code, I suspect.

What you appear to be attempting to do is link up the view and the model in the view’s init function, and that’s fine, but you’re on your own if you do that- which means you need to set up the model <-> view relationship yourself (which you have solved by passing the model as a parameter to the view init function).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)