moviepilot/chaplin — Issue #7: Delegate Events from Collection View for sub-views
Author: cpsubrian
Created: 2012-03-07 21:11:23+00:00
State: open

Imagine the scenario where you have a `

` of `
`'s that contain clickable `` tags. As far as I an tell the convention in Chaplin would be to have a Collection view for the `

`'s, an 'item' view for the `
`'s, and then to @delegate the `` clicks from the 'item' view.

The problem with this is that is binds events to every `
` view. This doesn't really take advantage of delegation at all, where you would ideally delegate from the `

` to the selector: `'li a'`. This would be only one event handler for the whole collection view. The problem is: you want the handler to be scoped to the item view that was clicked.

Is there an already established patter to do this? The challenge is the event handler is on the collection view, and it needs to somehow (from the DOM element passed back by jQuery) establish which item view instance to bind to. I suppose the `id` attribute could be used?