backbone.js events and el

后端 未结 1 1235
半阙折子戏
半阙折子戏 2021-02-13 19:35

Okay, so I\'ve read several other questions regarding Backbone views and events not being fired, however I\'m still not getting it sadly. I been messing with Backbone for about

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-13 20:31

    Your problem is that the events on GridView:

    events: {
        'click .grid-view': 'okay'
    }
    

    say:

    when you click on a descendent that matches '.grid-view', call okay

    The events are bound with this snippet from backbone.js:

    if (selector === '') {
      this.$el.on(eventName, method);
    } else {
      this.$el.on(eventName, selector, method);
    }
    

    So the .grid-view element has to be contained within your GridView's this.el and your this.el is

    . If you change your events to this:

    events: {
        'click': 'okay'
    }
    

    you'll hear your cows (or "hear them in your mind" after reading the alert depending on how crazy this problem has made you).

    Fixed fiddle: http://jsfiddle.net/ambiguous/5dhDW/

    0 讨论(0)
提交回复
热议问题