我有一个名为的顶级应用程序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 视图中启动它:
<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
不能将一个模块拆分为多个文件吗?这是我能想到的唯一事情发生在这里。还有什么可能导致问题?