所以我从 Backbone.js 扩展了一些对象:
var MyModel = Backbone.Model.extend({});
var modelInstance = new MyModel();
var MyModelView = Backbone.View.extend({});
我正试图弄清楚如何将我的模型绑定(bind)到它相应的 View 。如何处理 Backbone 中的数据绑定(bind)?
最佳答案
您在创建模型实例时将其传递到 View 中。
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.
关于javascript - Backbone : How To Bind A Model To A View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15720738/