所以我从Backbone.js扩展了一些对象:
var MyModel = Backbone.Model.extend({});
var modelInstance = new MyModel();
var MyModelView = Backbone.View.extend({});
我正在试图弄清楚如何将我的模型绑定到相应的View。如何在Backbone中处理数据绑定?
答案 0 :(得分:3)
您在创建模型实例时将其传递到视图中。
var modelView = new MyModelView({model: modelInstance})
来自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.