gpt4 book ai didi

javascript - Marionette:检查布局是否有另一个对象的实例

转载 作者:行者123 更新时间:2023-11-28 20:02:42 25 4
gpt4 key购买 nike

我正在寻找一种方法,如果布局的实例已在使用中,则无需重新渲染布局。在索引下方创建一个新的 PreactivationLayout,然后将其绑定(bind)到应用程序对象的主要区域。然后,如果您要访问 page2,我想检查 PreactivationLayout 是否正在使用;如果是这样,只需交换区域,如果不是,则创建一个新实例并将其添加到应用程序对象中。

class IndexController extends Marionette.Controller
initialize: (options)->
@app = options.app

index: ->

layout = new PreactivationLayout()

@app.main.show layout
layout.main.show new IndexView()

page2: ->

// Is the current layout an instace of the Preactivation class?

最佳答案

您可以执行类似的操作,这将检查当前区域内的 View 是否具有相同的构造函数。

if(!layout.main.currentView || layout.main.currentView.constructor !== PreactivationLayout){
layout.main.show(new PreactivationLayout());
}

或者正如 Tan Nguyen 在评论中建议的那样,

if(!layout.main.currentView || !(layout.main.currentView instanceof PreactivationLayout)){
layout.main.show(new PreactivationLayout());
}

关于javascript - Marionette:检查布局是否有另一个对象的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21394009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com