javascript 如何在渲染另一个视图之前清除视图?主干.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7388049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear views before rendering another one? Backbone.js
提问by fancy
Multiple view instances are happening in my application when I change layouts. I think it's possibly because they use the same el
but I'm not sure. How would I go about clearing out views before setting up new ones? Or should I create wrapper el
element for each one and clear them from the dom instead?
当我更改布局时,我的应用程序中会发生多个视图实例。我认为这可能是因为他们使用相同的el
但我不确定。在设置新视图之前,我将如何清除视图?或者我应该el
为每个元素创建包装元素并从 dom 中清除它们?
Thanks!
谢谢!
回答by Derick Bailey
you're probably running into zombie views caused by left-over bindings to various types of events. the solution i provided here will help you with that: Disposing of view and model objects in Backbone.js
您可能会遇到由遗留绑定到各种类型的事件引起的僵尸视图。我在此处提供的解决方案将帮助您解决此问题:在 Backbone.js 中处理视图和模型对象