0
votes

I'm trying to render two instances of an ItemView into different regions. When I do this, only one region appears with the working javascript. Both instances have their html elements.

I have two files that are both Layouts. One calls

 var monthView = new CalendarView({ parentDivName: "full_screen" });
 App.mainRegion.show(monthView);

The other calls:

  var monthView2 = new CalendarView({ parentDivName: "full_screen22" });
  App.datePickerRegion.show(monthView2);

Does anyone have a fiddle they can share where two instances of an ItemView are rendered on the same page where the javascript within the ItemView can be visible? Or, am I going about this all wrong? Is there a better way to create multiple instances of the same ItemView?

1
I don't think there's enough code here to allow anyone to help you without stabbing in the dark. Can you create a fiddle that demonstrates the issue?net.uk.sweet
MarionetteCollectionView demonstrates that it is perfectly fine to have multiple instances of a view. Your problem lies elsewhere.Robert Levy

1 Answers

1
votes

I imagine the problem lies elsewhere in your code as this is both valid code and a valid approach to rendering multiple instances of an ItemView. Without more code, it will be hard to figure out what exactly is the problem. One thing to check is that the layout has been rendered before trying to render something in one of its regions. Here's a simple jsfiddle that demos what I think you're going for: http://jsfiddle.net/craigjennings11/jxu9j/

var Layout = Backbone.Marionette.Layout.extend({
    el: '.layout',
    template: _.template('<div class="view1"></div><div class="view2"></div>'),
    regions: {
        view1: '.view1',
        view2: '.view2'
    }
});