1

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?

4

1 回答 1

3

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.
于 2013-03-30T16:22:10.363 回答