2013-08-30 47 views
1

我正在使用nicEdit的基於Ember.js的平臺上工作。這裏是我的代碼如何從nicEditor + emberjs中刪除事件

RichHTMLView = Ember.TextArea.extend({ 
    id: null, 
    editor: null, 
    didInsertElement: function(){ 
     var view = this; 

     view.id = this.get("elementId"); 

     view.editor = new nicEditor({ 
       buttonList : ['bold','italic','underline','right','center','justify', 'link', 'ul', 'ol'] 
     }).panelInstance(view.id); 

     //When the editor looses focus the content of the editor is passed to descr 
     view.editor.addEvent('blur',function(){ 
      view.get('controller').set('descr',view.getViewContent()); 
     }); 

     //So the editor looks nice 
     $('.nicEdit-panelContain').parent().width('100%'); 
     $('.nicEdit-panelContain').parent().next().width('100%'); 
    }, 
    getViewContent: function(){ 
     var view = this, 
      inlineEditor = view.editor.instanceById(view.id); 
     return inlineEditor.getContent(); 
    }, 
    willClearRender: function(){ 
     var view = this; 
    } 

}); 

所以這個只要我哪些主機視圖頁面上工作得很好,但如果我過渡到另一條路線,認爲有一些剩菜,即編輯器被破壞,但我假設nicEdit跟蹤事件綁定,所以我最終將blur事件綁定到編輯器,即在新的上下文中undefined,因爲視圖不存在。

我最好的猜測是我需要以某種方式解除willClearRender中的編輯器,但我不知道如何。

回答

0

,因爲我沒有得到答覆,nicEdit被放棄加入removeEventbkEvent我爲了解決這個問題做了一些修改的源代碼:

removeEvent: function(A, B){ 

if (B){ 
    this.eventList = this.eventList || {}; 
    this.eventList[A] = this.eventList[A] || []; 
    this.eventList[A].splice(this.eventList[A].indexOf(B),1); 
} 

然後,我可以在willClearRender刪除事件:

view.editor.removeEvent('blur',view.onBlur); 

要知道,我還沒有與多個編輯器進行了測試,因爲我需要不需要,但如果你有多個編輯器使用相同的回調沒有定義的行爲。