I have recently updated to Marionette JS version 2.4.7 after being on an older version of Marionette for a very long time.
I am initializing a module
and want to pass two objects to this module
, a model
and another custom object foo
.
layout = new FooBar.Layout
model: options.model if options.model
foo: options.foo if options.foo
options.loadRegion.show(layout)
The model comes through just fine in the initialize
method of the FooBar module but the foo
object is not coming through in the options
object of the FooBar module no matter what I try, though it is appearing in the options
object before I initialize FooBar.Layout
(as seen above).
Am I doing something wrong in the new version of Marionette?
I realized the problem was with trying to run a conditional statement in an object property declaration, which does not work.
layout = new FooBar.Layout
model: options.model if options.model
foo: options.foo if options.foo
Removing the conditional statements works:
layout = new FooBar.Layout
model: options.model
foo: options.foo
Or declaring your object before creating the new Layout works, as well
opts = nil
opts.model = options.model if options.model
opts.foo = options.foo if options.foo
layout = new FooBar.Layout(opts)
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.