Reputation: 622
This is a code fragment of my ItemView:
class List.GridRow extends Backbone.Marionette.ItemView
tagName: 'tr'
triggers:
'click': 'row:clicked'
Then in my Composite view I am doing this:
class List.GridView extends Backbone.Marionette.CompositeView
template: 'mapping/list/templates/grid'
itemView: List.GridRow
itemViewContainer: 'tbody'
initialize: (options) ->
@listenTo @, 'itemview:row:clicked', (itemView, data) -> @rowClicked(itemView, data)
rowClicked: (clickedItemView, data) =>
# I need the original event information to check of the ctrl or shift key was pressed?
#if !e.ctrlKey && !e.shiftKey
What I am trying to do here is to pass the original event information into the trigger handler but I haven't figure it out yet? Is there a way to do this with Marionette? Am I missing something?
Thanks!
Upvotes: 2
Views: 3590
Reputation: 72858
The intent of the triggers
is to provide a minimal event configuration for minimal needs within the view, while also preventing leaky abstractions. Passing the original event args out of the view breaks the abstraction of the view, which is what should be in control of the event args.
If you need the control and shift key information, you'll want to avoid the triggers
configuration and use standard events that publish the info you need.
class List.GridRow extends Backbone.Marionette.ItemView
tagName: 'tr'
events:
'click': 'rowClicked'
rowClicked (e) ->
@trigger "row:clicked",
control: e.ctrlKey,
shift: e.shiftKey
Upvotes: 7