javascript - Backbone : How To Bind A Model To A View

标签 javascript data-binding backbone.js

所以我从 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/

相关文章:

javascript - 异步函数的js生成器

javascript - jQuery UI 的 sortable() 的轻量级替代品?

Android 数据绑定(bind)未显示

javascript - Browserify 模块中的主干 View - 不工作

javascript - 未捕获的类型错误 : Object [object Window] has no method 'each' function

javascript - Backbone.js 为什么我必须使用下划线 (_.each) 来定位模型?

javascript - Sails.js:从 Controller 调用YouTube服务

javascript - 如何在 NodeJS 的路由中使用 "?param=X"?

wpf - 我总是需要为日期格式编写转换器吗?

c# - 使用转换器 WPF 绑定(bind)来自另一个 cs 文件的属性