0

下面是我的 html 页面/views 页面包括我的问题是如何在我的 view/js 文件中包含我的切换功能

营地.html

 <table cellpadding="0" cellspacing="0" border="0" class="camp" id="camp">

    <tr>
     <th width="5%"><input type="checkbox" onChange="toggle(this)" class="tick_mark" /></th>
     <th width="45%">Campaign Name</th>
    </tr>
  </table>

EDIT 意见/camp.js

     define([
        'jquery',
        'underscore',
        'backbone',
        'text!templates/camp.html',
        'collections/camp',
        'views/campviews',
        'constants'
        ], function( $, _, Backbone,  allcamp, Campaignscollection, Campaignsview, Constants ) {
           if (!CM.Views) {
              CM.Views= {};
           }
           CM.Views.camp = Backbone.View.extend({

           template: _.template(allcamp),

           initialize: function() {
              this.on("change:name", function(model){
                     var name = model.get("name"); // 'Stewie Griffin'
                     alert("Changed my name to " + name );
                 });
              _self = this;
              this.campaigns = new Campaignscollection();
              this.campaignsview = new Campaignsview({collection:this.campaigns});
              this.campaigns.fetch({
                 success: function () {
                 // _self.render();   
                      $(_self.el).find("#camp").append(_self.campaignsview.render().el);

                 }
              });
           },
   events:{
    'change .tick_mark': 'toggle'
    },
  toggle : function(){
     alert("//");
  }, 

           toggle: function( newChildsName ){
                 //this.set({ child: newChildsName });
              alert("in toggle");
             },
           render: function() {
              $(this.el).html(this.template());
              return this;
           }
        });

        return CM.Views.camp;
     });
4

1 回答 1

0

我认为正确的方法(不显眼)是在输入上放置一个 id 或一个类:

<th width="5%"><input type="checkbox" id="myInput" /></th>

然后在您的视图中将事件侦听器附加为:

events:{
        'change #myInput': 'toggle'
        }
于 2013-07-08T12:50:36.120 回答