Template two models in one view - Backbone/Marionette

后端 未结 2 1257
迷失自我
迷失自我 2021-02-09 02:08

I\'m trying to use two models in one view, and template using both of them. I\'m working with Marionette. Here is me initialization of the view:

main_app_layout.         


        
2条回答
  •  孤街浪徒
    2021-02-09 02:38

    You can override the serializeData method on your view and have it return both models' data:

    
    APP.Views.HeaderView = Backbone.Marionette.ItemView.extend({
    
      // ...
    
      serializeData: function(){
        return {
          model1: this.model.toJSON(),
          model2: this.options.model2.toJSON()
        };
      }
    
    });
    

    Then your template would look like this:

    
    

提交回复
热议问题