- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Backbone Marionette 应用程序出现问题,我的 subview 没有被完全破坏。您如何正确销毁要替换为另一个布局/项目 View 的嵌套布局 View ?
我对 Marionette documentation on destroying layout views 印象深刻,当我设置一个区域来显示新 View 时,旧 View 被破坏。但是,通过 vent 触发的事件仍然对据称已被破坏的旧 View 可见。
我在这里创建了这个问题的示例:https://jsfiddle.net/dhardin/5j3x2unx/
我认为问题出在我的路由器上:
App.Router = Marionette.AppRouter.extend({
routes: {
'': 'showView1',
'view1': 'showView1',
'view2': 'showView2'
},
showView1: function() {
var view1 = new App.View1();
App.Layout.mainRegion.empty();
App.Layout.mainRegion.show(view1);
},
showView2: function() {
var view2 = new App.View2();
App.Layout.mainRegion.empty();
App.Layout.mainRegion.show(view2);
}
});
根据我的理解,App.Layout.mainRegion.empty() 不是必需的,因为在区域管理器中销毁 View 时会处理此问题 显示() 功能。要查看问题,请通过导航导航到另一个 View ,然后单击按钮。您将看到针对旧 View 和新 View 都触发了警报。
回到我的 pre-marionette 应用程序中,我遵循了一种清理模式来避免讨论的这些内存泄漏 here .
本质上,当我的应用更改为新 View 时,我显示的 View 会调用以下函数:
Backbone.View.prototype.close = function(){
this.remove();
this.unbind();
}
如果您需要任何其他信息,请告诉我。提前致谢!
最佳答案
对于此类情况,您应该利用 onDestroy
函数来执行超出 Marionette 提供的额外清理工作。当 View 被替换或删除时,Marionette 会自动调用 onDestroy
。
onDestroy: function() {
App.vent.off('ButtonClicked', this.onButtonClicked, this);
}
来自 Marionette 文档:
By providing an onDestroy method in your view definition, you can run custom code for your view that is fired after your view has been destroyed and cleaned up. The onDestroy method will be passed any arguments that destroy was invoked with. This lets you handle any additional clean up code without having to override the destroy method.
在这里查看工作 fiddle :https://jsfiddle.net/ocfn574a/
请注意,我确实更新了您的路由配置中的拼写错误:'showVeiw1'
-> 'showView1'
关于javascript - Backbone Marionette - 布局 View 僵尸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37213561/
我真的不明白它们是如何有用的。原文article引入了初始化程序,这是代码示例: App = new Backbone.Marionette.Application(); App.addInitial
我正在准备使用 Backbone Marionette 迁移我的应用程序,但路由中出现错误: window.App = new Backbone.Marionette.Application
我正在尝试将 marionette.js 用于我的 Backbone 应用程序,但我对如何组织布局/区域并呈现它们感到有些困惑。 我正在寻找具有嵌套布局和区域的示例应用程序,以便我能更好地理解它。有什
我有一个带有区域的布局。当 Layout 初始化时,我希望它自动初始化一个预设 View 以进入它的区域,并在 Layout 本身显示/关闭时显示/关闭它。 当前示例来自 https://github
//当我点击 kickassessor 按钮时,它会更新数据库,但 View 不会更新。这是我的代码。 返回 Marionette.ItemView.extend( { initialize
我有需要显示/编辑的数据,这些数据似乎与 Marionette 提供的内置 View 不自然。让我举个例子来说明。 假设我想列出/编辑书籍。每本书都有一个 ISBN、一个书名和 0 个或多个标签。基本
我一直在查看各种 Marionette 问题,但没有找到我想要的,希望有人能给我一些合理的建议和一些建议。我是新手,只是想在我在 github 上选择的样板启动包上构建 https://github.
随着我的应用程序的增长,我觉得需要更结构化的路由器/ Controller 设置。 Marionette 文档提到以下内容: It is recommended that you divide you
在我的应用程序中,我添加了 Marionette.sync 插件并覆盖这些方法: Backbone.Marionette.TemplateCache.prototype.loadTemplate =
我想知道是否有可能以某种方式扩展 Marionette Layout 机制基于创建一种类似导航的堆栈。 Marionette 行为。 在区域 show() 的 View 之前,它会在当前显示的 Vie
看起来 Backbone.Marionette View 为事件等操作 DOM,所以我猜这不像更改基类引用那样微不足道,例如Backbone.View 到 BaseView。 有没有人解决过这个问题?
我正在使用 Marionette Layout .show渲染 CollectionView并想知道是否有办法检测 全部 ItemView children 已经完成了渲染? 我的代码的简化版本是:
因此,我不确定我是否完全理解应该如何触发此回调。如果您采用准系统模型、集合和 View : PatchModel = Backbone.Model.extend({}); PatchCollectio
我正在查看 Backbone Marionette,它似乎对我当前的项目很有前途。但是,无论 startWithParent 设置如何,添加模块时它们似乎都会自动启动。这是我遇到问题的一段代码(其中一
我是 Marionette 的新手,无法理解事件... 我有一个触发事件的 ItemView,我想在应用程序级别接收此事件,但是当我的应用程序监听此事件时,没有任何 react ... 如果事件聚合器
我有一个 CollectionView class MyCollectionView extends Backbone.Marionette.CollectionView itemView: My
我有一个复合 View ,在将模型添加到 View 集合时抛出以下错误:Uncaught ItemViewContainerMissingError: Missing itemViewContaine
我已经建立了一个项目,在其中扩展了包含两个不同区域的 Backbone.Marionette.Layout。该布局可以用作整个应用程序的组件。特别是,区域设置如下。 regions : { m
基本上,我试图将 CompositeView 呈现为一个简单的四列列表,其中包含一个表头,其中集合中的每个模型都呈现为一个并附加到 .我正在关注 an example of Derick's非常接近,
我正在尝试包含应用程序实例以使用其事件聚合器,如图所示 here 当我将实例包含在 View 中时,出现错误。 在 Requirejs 配置文件中启动 App.Bootloader.js: requi
我是一名优秀的程序员,十分优秀!