问题描述
我要当一个Backbone.js的视图被移除火的功能。我猜是这样一个去构造函数。在code以下是摘录我写的;我知道这是行不通的。不过,我记得怎么写,做这样的功能在过去看到的视频教程。我需要运行一个解构造函数的原因是为了清除间隔视图时去掉一个视图中设置的。
ViewWeather = Backbone.View.extend({
区间:的setInterval(函数(){的console.log('间隔火');},1000) //由功能
拆解:功能(){
//如果视图被删除
clearInterval(this.interval); }
});VAR viewweather =新ViewWeather();
本博客文章应该给你一些更好的信息
http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/
最显着的部分。
Backbone.View.prototype.close =功能(){
this.remove();
this.unbind();
如果(this.onClose){
this.onClose();
}
}
然后
MyView的= Backbone.View.extend({
初始化:功能(){
this.model.bind(变,this.render,这一点);
},
渲染:功能(){...}, 的OnClose:函数(){
this.model.unbind(变,this.render);
}});
I need to fire a function when a Backbone.js view is removed. I guess something like a de-constructor. The code below is a snippet I wrote; I know it won't work. However, I do remember seeing in the past a video tutorial on how to write a function that does this. The reason I need to run a de-constructing function is to clear the interval set inside a view when the view is removed.
ViewWeather = Backbone.View.extend({ interval: setInterval(function() {console.log('interval fire');}, 1000), // made up function deconstructor: function () { // if the view is removed clearInterval(this.interval); } }); var viewweather = new ViewWeather();
This blog post should give you some better info
most notable parts
Backbone.View.prototype.close = function(){
this.remove();
this.unbind();
if (this.onClose){
this.onClose();
}
}
and then
MyView = Backbone.View.extend({
initialize: function(){
this.model.bind("change", this.render, this);
},
render: function(){ ... },
onClose: function(){
this.model.unbind("change", this.render);
}
});
这篇关于上卸下摆臂Backbone.js的火灾事件()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!