gpt4 book ai didi

.remove() 上的 Backbone.js 触发事件

转载 作者:行者123 更新时间:2023-12-01 12:46:00 25 4
gpt4 key购买 nike

我需要在删除 Backbone.js View 时触发一个函数。我想像解构函数一样。下面的代码是我写的一个片段;我知道这是行不通的。但是,我确实记得过去看过一个视频教程,介绍如何编写执行此操作的函数。我需要运行解构函数的原因是在删除 View 时清除 View 内设置的间隔。

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();

最佳答案

这篇博文应该会给你一些更好的信息

http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/

最显着的部分

Backbone.View.prototype.close = function(){
this.remove();
this.unbind();
if (this.onClose){
this.onClose();
}
}

然后

MyView = Backbone.View.extend({
initialize: function(){
this.model.bind("change", this.render, this);
},
render: function(){ ... },

onClose: function(){
this.model.unbind("change", this.render);
}

});

关于.remove() 上的 Backbone.js 触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9513194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com