绑定到外部模型的更改
Binding to change of external model
我有一个带有模型的骨干视图。
此外,我有一个全局模型,其中包含一些特定于应用程序的东西。
现在,我将此模型的更改事件绑定到视图的渲染方法,但这似乎不起作用。
model: new Preferences.Item(),
render: function() {
$(that.el).html(template(that.model.toJSON()));
},
initialize : function() {
this.render = _.bind(this.render, this);
// global account model holder
App.Storage.account.bind("change", this.render);
},
我是否必须执行一些特定的绑定以附加到外部模型的事件?
您应该使用 Backbone 的内联绑定来绑定 render
方法。另外,您在render
方法中使用了that
,这将是关于它的错误。
var ModelView = Backbone.View.extend({
model: new Preferences.Item(),
template: _.template('<div><%= variable %></div>');
render: function () {
this.$el.html(this.template(this.model.toJSON()))
},
initialize: function () {
App.Storage.account.on('change', this.render, this);
}
});
找到了解决方案...您必须致电:
App.Storage.account.on("change", this.render)
相关文章:
- 在挖空中引用对象构造函数外部视图模型的属性
- 如果外部应用程序更改了持久模型(服务器数据库),AngularJS 是否可以自动更新视图
- 主干销毁集合外部的模型
- 如何通过单击来自javascript外部的复选框来更新AngularJS模型
- 如何将外部 API 中的其他数据添加到集合中的现有模型
- 如何使用来自外部源的数据更新 ng 模型
- 绑定到外部模型的更改
- 我可以在挖空时调用视图模型外部的函数吗?
- 从控制器外部访问模型数据's在AngularJS中的作用域
- 更新控制器外部的角度模型
- 从视图模型外部调用knockout.js中的函数
- 从外部脚本与angularjs模型进行通信
- ngRepeat-ed 指令表示外部模型的字段
- 主干模型——如何从事件处理程序执行外部函数
- 将数据从外部模型绑定到angularjs
- 如何从外部json文件绑定qooxdoo表模型
- RestMVC.js(猫鼬),Node.JS -外部模型文件
- 如何从jsp外部的js中读取模型属性
- 使用下划线外部模板在背部骨骼中设置模型内容
- 如何从模型外部访问模态实例$scope