0

I want to retrieve a model of particular id number into my view. Here are how my controller looks like (API is working fine):

Controller

var EventController = Marionette.Controller.extend({
    initialize: function(options){
        this.model = options.model;
        this.mainRegion = options.mainRegion;
    },

    edit: function(id) {
        var _me = this;
        //this is my model
        var event = new Event({
            id: id
        });
        event.fetch({
            success: function(){
                 //this is my layout
                _me.eventLayout = new EventView({
                    model: event
                });
                _me.mainRegion.show(_me.eventLayout);
            }
        });
     }
});

The scenario is like:

  • My controller functions are getting called using a router.
  • My main Layout i.e. eventLayout contain some regions which are eventViews all in Marionette.
  • The model.fetch is successful and I can see the details fetched from the API.
  • All the subviews of the mail Layout are getting rendered perfectly.
  • None of the data meant for main Layout template is getting rendered . Its just the DOM that gets rendered but not the data.
  • I think both _me.eventLayout and _me.mainRegion are called approximately at same time so _me.mainRegion is rendered even if _.wrap method is not there properly. So try to make _me.mainRegion render after _me.eventLayout. You can use _.wrap method. Hope this helps. You can refer to http://stackoverflow.com/questions/12004534/backbonejs-rendering-problems – DimoMohit Sep 30 '14 at 05:26

1 Answers1

0

Try this:

edit: function (id) {
   var _me = this, event, eventView;

   event = new Event({ id: id });
   eventView = new EventView({ model: event });

   event.fetch().done(function () {
       _me.mainRegion.show(eventView);
   });
}
knpsck
  • 833
  • 8
  • 8