I would like to use the bubling behaviour of collection views but it doesn’t seem to work.
A bit of context: I display a modal AddPartFromPurchase that show a table populated with a collectionView. This works well.
When the user clicks a row, the itemview triggers the purchase:chosen event so according to the documentation, I expect the collection view to receive the itemview:purchase:chosen event but no such event is ever triggered: neither in AddPartFromPurchase or Purchases. 🙁
Here is the example code.
AddPartFromPurchase = Backbone.Marionette.ItemView.extend
template: 'pages/vehicles/modifications/add_part_from_purchase'
initialize: (attributes)->
@purchases = attributes.purchases
onRender: ->
view = new Purchases(el: @$('tbody'), collection: @purchases)
@bindTo(view, 'all', @foo)
view.render()
foo: (event, foo, bar, baz)->
console.log(event, foo, bar, baz)
Purchase = Backbone.Marionette.ItemView.extend
template: 'pages/vehicles/modifications/purchase'
tagName: 'tr'
events:
'click' : 'selectPurchase'
selectPurchase: ->
@trigger('purchase:chosen', @model)
false
serializeData: ->
purchase: @model
part: @model.get('part')
Purchases = Backbone.Marionette.CollectionView.extend
itemView: Purchase
initialize: ->
@bindTo(@, 'all', @foo)
foo: (event, foo, bar, baz)->
console.log(event, foo, bar, baz)
Maybe I’m doing it wrong, I feel bad about defining the listener in the onRender, but as I use a el I can’t do that in initialize.
How can I deal with that?
Answer based on comment stream: be sure you’re on v0.7.6 or higher, when this feature was introduced.