Design a puppet region after a model has been selected

I would like to use the approach described by Derick Bailey in the “ General Problem Solving ” section of this thread to display the view after the model is retrieved. I will communicate his solution here:

 MyView = Backbone.View.extend({
  initialize: function(){
    this.model.on("sync", this.render, this);
  },

  render: function(){ ... }
});


myModel = new MyModel({id: someId});
new MyView({
  model: myModel
});

myModel.fetch();

I have a slightly different situation: my view is inside the layout of the region. If I call Marionette.Region.show (), it works, but the view is displayed twice. The call to Marionette.Region.attachView () renders the view rendering function once, but the content does not appear on the page.

Any idea?

+5
source share
2 answers

You can wait until the model is synchronized until the view is displayed.


var myView = new MyView({
  model: myModel
});

myModel.on("sync", function(){
  myRegion.show(myView);
});

myModel.fetch();
+13

. , , Derick . , . :

, . updateView, , render() .

, - .

var myView = new MyView({
     template: loader,
     initialize : function(){
        this.model = new MyModel();
        this.model.on("sync", this.updateView, this);
        this.model.fetch();
     },
     updateView : function(){
        this.template = myTemplate;
        this.render();
     }
});
+4

All Articles