销毁或删除Backbone.js的视图 [英] Destroy or remove a view in Backbone.js

查看:123
本文介绍了销毁或删除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();
};

这篇关于销毁或删除Backbone.js的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆