简体   繁体   中英

Backbone Marionette Multiple instance not rendering javascript

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?

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'
    }
});

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM