Backbone.View中的多个el

时间:2013-04-11 07:26:15

标签: javascript backbone.js

例如我有:

Job.Views.Response = Backbone.View.extend({
el: '.ra-response-button',
    events: {
      "click" : "alert"
    },

    alert: function() {
       console.log(this.$el);
    }; 
)};

我有多个按钮(按钮)。 我只想点击按钮就能完成这项工作。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

el更改为按钮的父元素,然后执行类似

的操作
 <div id="buttonWrapper">
    <input type="button" id="button1" />
    ... snip ...
 </div>

查看:

  Job.Views.Response = Backbone.View.extend({
     el: 'buttonWrapper',
     events: {
      'click #button1': 'eventHandler1', 
      'click #button2': 'eventHandler2',
      ... And so on...
   }