gpt4 book ai didi

javascript - 我的一些应用程序初始化程序似乎没有触发?

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

我有一个名为 SearchApp 的顶级应用程序,它有一个名为 TeamApp 的子应用程序。这些文件的结构如下:

search_app.js.coffee # The top-level application.
team_app/
app.js.coffee
team_list.js.coffee
team_invite.js.coffee

我在 search_app.js.coffee 中初始化我的应用程序:

window.Domainer = {}

# This is the top level application.
Domainer.SearchApp = new Backbone.Marionette.Application()

# Assign a region to the Application.
Domainer.SearchApp.addRegions(stage: '#stage')

并在 html View 中启动它:

<script>Domainer.SearchApp.start({});</script>

子模块TeamApp分布在几个文件上(如下)。问题在于,TeamApp 模块中的某些文件似乎无法向 SearchApp 添加初始化程序。我可以从一个文件中的初始化中 console.log 而不能在另一个文件中这一事实证明了这一点。

# team_app/app.js.coffee
Domainer.SearchApp.module "TeamApp", (TeamApp, SearchApp, Backbone, Marionette, $, _) ->

# Initializers
# ----------

SearchApp.addInitializer (options) ->
console.log "This will log when I call Domainer.SearchApp.start()"

# In coffeescript it's important to explicitly return.
return TeamApp

# team_app/team_list.js.coffee
Domainer.SearchApp.module "TeamApp", (TeamApp, SearchApp, Backbone, Marionette, $, _) ->

class CompactSearcher extends Marionette.ItemView
# ... various code relating to this view.

class TeamList extends Marionette.CollectionView
# various code relating to this view.

SearchApp.addInitializer (options) ->
console.log "This will never log for some reason."

return TeamApp

# team_app/invite_view.js.coffee
Domainer.SearchApp.module "TeamApp", (TeamApp, SearchApp, Backbone, Marionette, $, _) ->

class InviteView extends Marionette.ItemView
# ... various code relating to this view.

SearchApp.addInitializer (options) ->
console.log "This will never log either."

return TeamApp

是否无法将一个模块拆分为多个文件?这是我唯一能想到的事情正在这里发生。还有什么可能导致这个问题?

最佳答案

仅供引用 - 我现在已经更新了 Marionette 以支持这种情况。



MyApp = new Backbone.Marionette.Application();

MyApp.module("Foo", function(Foo){
Foo.def1 = true;
});

MyApp.module("Foo", function(Foo){
Foo.def2 = true;
});

MyApp.Foo.def1; //=> true
MyApp.Foo.def2; //=> true

关于javascript - 我的一些应用程序初始化程序似乎没有触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10621213/

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