繁体   English   中英

在视图的event属性中使用backbone.js监听与@el相关的事件

[英]Listen events relative to the @el with backbone.js in the event attribute of a view

我写这样的观点:

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

我想在事件数组中添加一个元素,像这样:

events:
   'click @el.find('img')' : 'myfunction'

我能做到吗? 我怎么能这样做? 我正在使用jQuery。

你不能'click @el.find('img')'但是'click img'相当于你想要做的 - 所以它更简单:)

它的工作方式是它将第一个空格之前的第一个单词作为事件类型,之后的所有内容都变成了jQuery选择器。 如果只传递没有选择器的事件名称,则事件将绑定到@el如果传递选择器字符串,它会将事件委托给@el.find selector_string

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM