Backbone Marionette get region view
Asked Answered
N

1

14

I have a marionette layout that has a region with a view inside. How can I get a reference to that view?

For example:

var layoutView = Backbone.Marionette.Layout.extend({
    regions: {
        myRegion: '.some-element'
    },
    initialize: function(){
        this.render();
        this.myView.show(new someView());
    },
    test: function(){
        var view = this.myRegion.get() // or something to retrieve the view?
    }
});

I mean, I can save the view instance into "this", but surely marionette must have a way of retrieving it...right?

Ninth answered 12/9, 2013 at 20:38 Comment(0)
Q
20

It should just be this.myRegion.currentView and model if bound to view: myRegion.currentView.model

Quinones answered 12/9, 2013 at 20:40 Comment(2)
i know for sure this works on regions bound to the main app. R u sure test runs after show?Quinones
you also have an error in initialize. it should be myRegion.show(...)Quinones

© 2022 - 2024 — McMap. All rights reserved.