I have a collection view (MyCollView
below), and want to (conditionally) inject html between the different itemViews (MyItemView
below) without modifying MyItemView
. I know there are lots of different options that CollectionViews can have, but didn't see anything for this particular use.
More specifics: I want to inject a <br>
tag after each MyItemView in the MyCollView
as long as the instance of MyItemView
is not the last in the collection.
Here's my desired output for what my collection view would render:
<div>name1</div>
<br>
<div>name2</div>
<br>
<div>name3</div>
Here's my code:
MyItemView = Backbone.Marionette.ItemView.extend({
template: _.template('<div><%= name %></div>')
});
MyCollView = Backbone.Marionette.CollectionView.extend({
childView: MyItemView
//ideally, I would like to provide some other property to accomplish my goal here, like...
//separatorHtml: '<br>'
});
var myColl = new Backbone.Collection([
{name: 'name1'},
{name: 'name2'},
{name: 'name3'}
]);
thisCollView = new MyCollView({
collection: myColl
});
thisCollView.render();
My thoughts now are to extend the MyItemView
into MyModifiedItemView
and put in this optional <br>
tag, but I didn't know if there was more of a "marionette-y" way to do it. Any thoughts? Thanks!