销毁或删除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.

我希望会有一个事件附加到控制器,这样,当一个新的请求通过它破坏了previous意见的然后加载新的。

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.

有没有办法做到这一点,而无需建立一个remove函数为每个视图?

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