【问题标题】:How to remove events from nicEditor + emberjs如何从 nicEditor + emberjs 中删除事件
【发布时间】: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 中的编辑器,但我不知道该怎么做。

【问题讨论】:

    标签: ember.js nicedit


    【解决方案1】:

    由于我没有得到回复并且nicEdit 已被放弃,我对源代码进行了一些更改,以便通过将removeEvent 添加到bkEvent 来处理此问题:

    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);
    

    请注意,我没有使用多个编辑器对其进行测试,因为我的需求不需要,但如果您有多个具有相同回调的编辑器,则未定义行为。

    【讨论】:

      猜你喜欢
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-13
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多