销毁或删除 Backbone.js 中的视图 [英] Destroy or remove a view in Backbone.js
问题描述
我目前正在尝试为视图实现销毁/删除方法,但我无法获得适用于所有视图的通用解决方案.
I'm currently trying to implement a destroy/remove method for views but I can't get a generic solution to work for all my views.
我希望有一个事件可以附加到控制器上,这样当一个新请求通过时,它会破坏以前的视图然后加载新的视图.
I was hoping there would be an event to attach to the controller, so that when a new request comes through it destroys previous views then loads the new ones.
有没有什么方法可以做到这一点,而不必为每个视图构建一个删除函数?
Is there any way to do this without having to build a remove function for each view?
推荐答案
在不知道所有信息的情况下...您可以将重置触发器绑定到您的模型或控制器:
Without knowing all the information... You could bind a reset trigger to your model or controller:
this.bind("reset", this.updateView);
当你想重置视图时,触发重置.
and when you want to reset the views, trigger a reset.
对于您的回调,请执行以下操作:
For your callback, do something like:
updateView: function() {
view.remove();
view.render();
};
这篇关于销毁或删除 Backbone.js 中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!