Should subviews display layouts?

A simple and short question: if a view contains two or more sub-views. Should a view container be a layout view?

If not, what are some good alternatives?

Update:

my code is:

var LikeButtonModal = Backbone.Model.extend({ url: 'api/profile/like/' }); var LikeButton = Backbone.Marionette.ItemView.extend({ tagName: 'button', className: 'like', template: '<div>like</div>', events: { 'click' : 'like' }, initialize: function(userId){ this.model = new LikeButtonModal(); }, like: function(){ this.model.save(); } }) var LeftProfileView = Backbone.Marionette.Layout.extend({ template: '#profile-left', regions:{ extra : '.extra' }, initialize: function(){ this.on("item:rendered", this.editable, this); }, onRender: function(){ if(this.model.get('userid') != ActiveUser.get('userid')){ this.extra.show(new LikeButton(this.model.get('userid'))); } } }); 
+4
source share
1 answer

Layouts are suitable for this if you replace the subviews at different times or if the subviews are very different types ... for example, a layout may contain your title, your navigation, and the main content area.

Other options are CollectionViews and CompositeViews.

Collection views will display a collection of items using the same view for each item in your collection. This works well for lists of things.

CompositeViews are CollectionViews that can display a wrapper pattern around a collection. For example, the structure of an HTML table. The table , thead , tbody and tfooter can be displayed in the CompositeView wrapper template, and then the collection of elements can be displayed in the tbody tag.

This may shed a bit more attention on this topic: https://github.com/derickbailey/backbone.marionette/wiki/Use-cases-for-the-different-views

+4
source

All Articles