I write my view like this :
class Remobs.Views.Element extends Backbone.View
template: JST['elements/element']
events:
'element_rended': 'initImagesDatas'
'click img.element_image' : 'observeImageEvents'
'click .more': 'addToBag'
'click .less': 'decreaseNumber'
tagName : 'li'
render: ->
$(@el).html(@template(element: @model))
@currentImage = $(@el).find('img')
@craftBox = null
$(@el).trigger('element_rended')
this
And i want to add an element in the events array like this :
events:
'click @el.find('img')' : 'myfunction'
Am I able to do that? And how can i do that? I am using jQuery.
you can’t do
'click @el.find('img')'but ‘click img’ is an equivalent of what you want to do – so it’s much simpler 🙂the way it works is that it takes the first word before first space as a event type and everything after that is turned into a jQuery selector. If you pass just an event name without a selector, event will be bound to
@elif you pass a selector string it will delegate the event to@el.find selector_string