0
votes

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?

1
what version of marionette are you using v0.7.6 introduced the event bubbling, and i use it a lot... seems odd that it's not working for you.Derick Bailey
Good point! I didn't even noticed that Marionette has evolved so much (apart your recent post about 0.9). I'm using 0.7.4, so I'll try with the 0.8.4. Thanks Derick.Romain Tribes

1 Answers

1
votes

Answer based on comment stream: be sure you're on v0.7.6 or higher, when this feature was introduced.