2012-02-01 151 views
3

因此,這是事情。我正在製作一個使用backboneJS的應用程序。我目前創建了不同行的列表。每一行都有一個帶有功能editRow的編輯按鈕和一個帶功能removeRow的刪除按鈕。目前editRow的作品,它創建了新的視圖,在這種情況下是一個模態窗口和它的app.EditRowView。這個視圖有另一個我無法綁定的按鈕。沒有被綁定的函數是modalWindow。 任何線索?我的邏輯錯了嗎?應該不應該創建其他視圖? 任何幫助都照常讚賞。創建視圖的骨幹視圖

 
    app.FormRowView = Backbone.View.extend({ 
     tagName:'li', 
     events: { 
      "click .danger"   : "removeRow", 
      "click .primary"  : "editRow" 

     }, 

     initialize:function(){ 
      var template =this.model.get('temp'); 
      _.bindAll(this, 'render'); 
      this.model.bind('change', this.render); 
      this.template = _.template($("#"+template).html()); 
     }, 

     render:function(){ 
      var renderedContent = this.template(this.model.toJSON()); 

      $(this.el).html(renderedContent); 

      $(function() { 
       $(".sortable").sortable(); 
       $(".sortable").disableSelection(); 
      }); 


      return this; 

     }, 

     removeRow:function(){ 
      $(this.el).remove(); 
     }, 

     editRow:function(){ 
      var view = new app.EditRowView({ 
       model:this.model, 
       collection: this.collection 
      }); 
      $("body").append(view.render().el); 
      return this; 
     } 

    }); 

    app.EditRowView = Backbone.View.extend({ 

     events: { 
      "click .save"  : "modalWindow" 
     }, 

     initialize:function(){ 

      var template =this.model.get('editScreenTemplate'); 
      _.bindAll(this, 'render'); 
      this.model.bind('change', this.render); 
      this.template = _.template($("#"+template).html()); 
     }, 

     render:function(){ 
      var renderedContent = this.template(this.model.toJSON()); 
      $(this.el).html(renderedContent); 
      return this; 

     }, 

     modalWindow:function(){ 
      alert("im in"); 

     } 
    }); 


基本上正在發生的事情是,該函數modalWindow永遠不會觸發。我有正確的元素(一個按鈕類與.save)在UI中

回答

0

嘿傢伙,所以我fiugured出來。我需要指定一個tagName以便委託事件綁定到該視圖... 感謝任何方式