Using Marionette.ItemView for views without models?

后端 未结 2 1739
长发绾君心
长发绾君心 2021-02-04 13:29

Is it conventional to use Marionette.ItemView for view classes that do not have a specific model property associated with them?

As Mario

2条回答
  •  渐次进展
    2021-02-04 13:37

    ItemView can be used without a model. I do this quite regularly.

    If you need to specify data for an ItemView, but not have that data in a Backbone.Model, you need to override the serializeData method:

    
    MyView = Marionette.ItemView.extend({
      serializeData: function(){
        return {
          my: "custom data"
        };
      }
    });
    

    the base Marionette.View isnt' meant to be used directly because it doesn't provide a render function on it's own. That doesn't mean you can't use it to create your own base view types, though. You could, for example, build a view type for your application that deals with rendering google maps or a third party widget or something else that doesn't need the general Backbone.Model based rendering that ItemView has in it.

提交回复
热议问题