Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Marionette Compositeview within a Layout region
    primarykey
    data
    text
    <p>I'm creating a portfolio type site. The project page shows general information about the project and a gallery.</p> <p>I've split it up, so the project page is a Marionette Layout. This layout renders information about the project within its own template and has a gallery region. I want to add a gallery composite view to this region. This will have a large image and a list of thumbnails. </p> <p><strong>Project Layout</strong></p> <pre><code>ProjectView = Backbone.Marionette.Layout.extend template: '#ProjectView' className: 'project__item' events: { 'click .close-project': 'closeProject' 'click #next': 'navigateProject' 'click #prev': 'navigateProject' } regions: { gallery: ".left" } initialize: -&gt; @galleryCollection = new GalleryCollection @model.get('images') onRender: -&gt; @galleryView = new GalleryCompositeView { model: @model, collection: @galleryCollection } @gallery.show @galleryView </code></pre> <p><strong>Gallery CompositeView</strong></p> <pre><code>GalleryCompositeView = Backbone.Marionette.CompositeView.extend template: '#gallery__composite' itemView: GalleryItemView itemViewContainer: '.thumbs' className: 'project__gallery' initialize: -&gt; console.log 'new GalleryCompositeView' </code></pre> <p><strong>Gallery Item View</strong></p> <pre><code>GalleryItemView = Backbone.Marionette.ItemView.extend tagName: 'li' className: 'gallery__item' template: _.template ''' &lt;div class="loading"&gt;LOADING&lt;span class="icon-loading"&gt;&lt;/span&gt;&lt;/div&gt; &lt;div class="image"&gt;&lt;/div&gt; ''' initialize: -&gt; console.log 'new GalleryItemView' </code></pre> <p>When I pass both the model and the collection to the composite view I get the error below, but when I pass just the model, it renders fine just without the thumbs. I can't see anything wrong with how I have setup my composite view.</p> <p>Its strange that GalleryCompositeView is being initialised twice.</p> <p>Any direction would be appreciated, thanks.</p> <p><img src="https://i.imgur.com/jK0n4ti.png" alt="Imgur"></p> <p><strong>Edit</strong> Turns out there where two issues, thanks daivd for pointing out the collection issue, I was just passing in an array or image paths. This was my fix</p> <pre><code> images = [] _.each @model.get('images'), ( el ) -&gt; images.push { src: el } @galleryCollection = new GalleryCollection images </code></pre> <p>The second error was declaring my CompositeView gallery view in my code before the thumb nail views. Changing the order fixed everything. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload