Real Dreams
Real Dreams

Reputation: 18010

Marionette show event does not be triggerd

I want execute show code after any showing any regions. I tried:

app.Layout = Backbone.Marionette.Layout.extend({
        template: "#layout-template",
        regions: {
            mini1: {
                selector: "#mini1",
                onShow: function () {
                    console.log("triggered!");
                }
            }});
app.layout.mini1.show(new view());

But the onShow function does not run. What is wrong with it?

Upvotes: 0

Views: 29

Answers (1)

Dmytro Yarmak
Dmytro Yarmak

Reputation: 1018

There are 3 way of defining region in list of region:

  1. String with selector
  2. Object with selector and regionType properties
  3. Region class

So when you pass object you can not specify onShow handler. But you can do what you want if you pass extended Marionette.Region:

var Layout = Backbone.Marionette.Layout.extend({
    template: "#layout-template",
    regions: {
        mini1: Marionette.Region.extend({
            el: "#mini1",
            onShow: function () {
                console.log("triggered!");
            }
        })
    }
});

You can check this solution here: http://jsfiddle.net/2CvzR/

And documentation is here: https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.region.md#custom-region-types

Upvotes: 2

Related Questions