backbone.js视图事件不被破坏
问题描述:
我试图摧毁一个视图/解除所有事件时,不再需要视图。我要做的就是:backbone.js视图事件不被破坏
view.$el.removeData().unbind();
view.undelegateEvents();
view.remove();
的观点被破坏了,我不能再看到DOM相关的元素,但事件似乎坚持。我正在使用Chrome开发人员工具并检查内存使用情况,我发现每次渲染视图并将其销毁时,事件侦听器都会增加一个。
我试图输出视图事件做:
this.$el.data("events");
,但是这给了我不确定。
有什么想法?
谢谢。
答
这个优秀的文章介绍如何防止内存泄漏在骨干:http://andrewhenderson.me/tutorial/how-to-detect-backbone-memory-leaks/
他完成常规摧毁一个观点是这样的:
this.unbind(); // Unbind all local event bindings
this.model.unbind('change', this.render, this); // Unbind reference to the model
this.options.parent.unbind('close:all', this.close, this); // Unbind reference to the parent view
this.remove(); // Remove view from DOM
delete this.$el; // Delete the jQuery wrapped object variable
delete this.el; // Delete the variable reference to this node
请问您查看包含孩子的意见?你应该解除绑定/删除它们 – jviotti 2013-04-05 20:44:13