zoukankan      html  css  js  c++  java
  • angularjs中ckeditor的destroy问题

    项目中,在切换了页面的tab页后会发现上传图片的操作报错,检查后发现问题根源是切换了tab页重新加载页面时ckeditor又会创建一次,这个时候的ckeditor已经不是第一次创建的那个了,所以上传图片的方法中会报错。

    解决方法:在ckeditor每次创建之前判断一下,如果有ckeditor则destroy掉,重新创建新的,保证页面上始终只有一个ckeditor,具体如下:

    • 在ckeditor的directive中:
      console.log(CKEDITOR.instances.myCKeditor ); //①
      if(CKEDITOR.instances.myCKeditor){//如果CKEDITOR已经创建存在则执行destroy                                
          CKEDITOR.instances.myCKeditor.destroy();
      }
      console.log(CKEDITOR.instances.myCKeditor);  //②   
      var ckeditor=CKEDITOR.replace(<HTMLTextAreaElement>element[0]);//保持始终创建新的CKEDITOR
      console.log(CKEDITOR.instances.myCKeditor);  //③
    • 说明:其中,myCKeditor是页面中textarea的name值
      <textarea ckeditor-Directive name="myCKeditor"></textarea>
    • 三个console.log打印的情况如下:
      •   首次进入页面时由于之前是没有ckeditor存在的,所以①和②都是undefined,执行创建代码后③是创建出来的ckeditor对象;
      •   切换了tab页后,①是之前创建的ckeditor对象,执行了destroy()方法后②是undefined,执行创建代码后③是新的ckeditor对象。
  • 相关阅读:
    svn使用方法
    董事、执行董事、总裁、总经理
    华联、联华、世纪华联、百联
    声明式编程和命令式编程
    NodeJS中的require和import
    JSONP跨站访问
    Camera服务之--架构浅析
    HashMap实现原理分析
    设计模式解读之一: 策略模式
    Java6.0中Comparable接口与Comparator接口详解
  • 原文地址:https://www.cnblogs.com/li-you/p/5999880.html
Copyright © 2011-2022 走看看