Reputation: 7181
So I have some objects extended from Backbone.js:
var MyModel = Backbone.Model.extend({});
var modelInstance = new MyModel();
var MyModelView = Backbone.View.extend({});
And I'm trying to figure out how to bind my Model to its corresponding View. How does one handle data-binding in Backbone?
Upvotes: 1
Views: 91
Reputation: 3429
You pass your model instance into the view when creating it.
var modelView = new MyModelView({model: modelInstance})
From the docs:
When creating a new View, the options you pass — after being merged into any default
options already present on the view — are attached to the view as this.options
for future reference. There are several special options that, if passed, will be
attached directly to the view: model, collection, el, id, className, tagName and attributes.
Upvotes: 3