I have create a marionette module like this
App.module("HeaderApp", function (HeaderApp, App, Backbone, Marionette, $, _) {
HeaderApp.on('start', function () {
...do something....
});
});
When I call App.module("HeaderApp").start()
the event listener does not fire, however if I manually trigger the event it will run.
Reading the marionette documentation it seems as though this should work. Any ideas?
More than likely, it's because the module auto-starts with the app and is therefore already running by the time you register the event listener.
To prevent auto start, set startWithParent
to false ( https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.application.module.md#preventing-auto-start-of-modules ) :
App.module("HeaderApp", function (HeaderApp, App, Backbone, Marionette, $, _) {
HeaderApp.startWithParent = false;
HeaderApp.on('start', function () {
...do something....
});
});
Then it should work as you expect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.