In a Marionette CollectionView, how can I pass the index of the model (in the collection) to the ItemView?
marionette
Solution
the `itemViewOptions`, when set up as a function, receives an `item` or `model` parameter. Use this to find the index:
class MyCollectionView extends Backbone.Marionette.CollectionView
itemView: MyItemView
itemViewOptions: (model) ->
{
indexInCollection: this.collection.indexOf(model)
}
Problem
I have a CollectionView ``` class MyCollectionView extends Backbone.Marionette.CollectionView itemView: MyItemView itemViewOptions: -> { indexInCollection: ? } ``` And I want MyItemView to know at which index in the collection its model is at. I suppose, in the MyItemView, I can find it out via ``` @model.collection.indexOf(@model) ``` But is there a way to pass it in directly into MyItemView from my Marionette CollectionView, using some internal Marionette mechanism? Is this index exposed somewhere already?