【发布时间】:2013-08-30 15:04:34
【问题描述】:
我正在开发基于 Ember.js 的平台,我使用 nicEdit。这是我的代码
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 中的编辑器,但我不知道该怎么做。
【问题讨论】: