English 中文(简体)
我的一些初步应用者似乎没有触发?
原标题:Some of my application initializers don t seem to trigger?

我有一个称为<代码>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>

The Submodule TeamApp is set out over a several file (below). 问题在于<代码>中的一些档案 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

不可能将一个单元分成多个档案? 这是我所能想象的唯一事情。 怎样才能造成问题?

最佳回答

You ask:

不可能将一个单元分成多个档案?

查阅backbone-marionette source证实,这恰恰是:

// Get the module name, and check if it exists on
// the current parent already
moduleName = moduleNames[i];
module = parentModule[moduleName];

if (!module){ 
  // This is where the module definition is used...
}

return module;

因此,如果你试图多次界定同一单元,则只使用第一个定义。

问题回答

FYI - 我更新了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




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签