currently I'm fiddling around with Marionette and Backbone (because I have to). I have a list of entities: CompositeView with ItemViews, every ItemView has a model with data like firstname and lastname.
In each ItemView is a link that will catch new data for the ItemView via AJAX (another endpoint!) and should update the view with a list of additional data like: [{"id": 1, "foo": "this is soo bar"}, {"id": 2, "foo": "a little bit of baz"}]. That data should be rendered then into the view (and can be removed again on a click).
What's the best way to go here? Adding a second model within the ItemView or add the new data to the existing view? Or something completely different? I appreciate every helpful tip!
My Solution (kind of)
Here is what I ended up with: when the link for the additional data is clicked, the associated ItemView instanciates a Backbone.Collection object I defined. That collection holds the URL for the endpoint. Then, I call the collection.fetch() method and render that collection with Underscore like this (roughly):
var tpl = _.template(dataTemplate);
var html = tpl({ myData: {collection.models});
node.html(html);
Thank you guys for thinking with me :)