Search code examples
backbone.jsmarionette

Multiple resources in one view


I want to display a list of images and their respective comments. Like:

Image url                    | Format        | Comments
http://example.com/img.jpg   | 1280x420      | [Comment 1], [Comment 2] ...show all  ...show all  
http://example.com/img2.jpg  | 630x590       | [Comment 1], [Comment 2] ...show all  

I have two resouces: /images and /comments/{image_id}

What is the recommended way to fetch the comments for each image to be able to display them on the same row? Does Marionette have a helper for this?


Solution

  • In my opinion, these look like a good place to use relational models. Backbone doesn't support these out of the box, so you'll need a plugin. Have a look at Backbone-Relational or supermodel.js. These projects provide better forms of model nesting than the default implementation. From there, use nested composite views to render the collections.