download1214 2015-10-09 04:57
浏览 77

Ckeditor实例无法破坏?

How i can destroy ckeditor instance?

i have a problem ckeditor instance double. i will to destroy it.

i will check code console.log(editorID) same in the images. I see the textarea if i add chapter1 i have 2 instance is textarea0 and textarea1. If i add chapter2 i have 3 instance is textarea0, textarea1 and textarea2. I think this code is not destroy instance. Can you help me for this issue? Thank you. I'm apologize. I'm not good at English.

enter image description here

    function loadEditors() {
        var $editors = $("textarea.editors");
        console.log($editors.length);
        if ($editors.length) {
            $editors.each(function() {
                var editorID = $(this).attr("id");
                var instance = CKEDITOR.instances[editorID];

                if (instance) { instance.destroy(true); }
                console.log(editorID);
                CKEDITOR.replace(editorID);
            });
        }
    }   

If i cut out ckeditor this code is work and attribute id textarea is true. See the code example.

    $(document).ready(function() {  

        //CKEDITOR.replaceAll('editors');   
        $("#chapter").on("click",function(){

            var i = $('.nav-tabs li').length;
            $('.nav-tabs li:last-child').clone().removeClass('active').appendTo(".nav-tabs").find('a').attr('href','#chapter'+i).attr('aria-controls','chapter-'+i).text("Chapter "+i);
            $('.tab-pane:last-child').clone().removeClass('active').appendTo(".tab-content").attr('id','chapter'+i);
            $('.tab-pane:last-child').find('textarea').first().attr('id','textarea'+i).val('textarea'+i);

            //loadEditors();
        });
        
/*     var $editors = $("textarea.editors");
        if ($editors.length) {
            $editors.each(function() {
                var instance = CKEDITOR.instances[$(this).attr("id")];
                if (instance) { $(this).val(instance.getData()); }
            });
        }*/
            
/*      function loadEditors() {
            var $editors = $("textarea.editors");
            console.log($editors.length);
            if ($editors.length) {
                $editors.each(function() {
                    var editorID = $(this).attr("id");
                    var instance = CKEDITOR.instances[editorID];
                    
                    if (instance) { instance.destroy(true); }
                    console.log(editorID);
                    CKEDITOR.replace(editorID);
                });
            }
        }*/     
        
    });
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="http://cdn.ckeditor.com/4.5.4/standard-all/ckeditor.js"></script>

<div class="pull-right"><button type="button" class="btn btn-default" id="chapter"><i class="fa fa-plus"></i> Add Chapter</button></div>
<div class="clearfix"></div>

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
  <li role="presentation" class="active"><a href="#chapter0" aria-controls="chapter0" role="tab" data-toggle="tab">Chapter 0</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="chapter0">
          <h3>Chapter 0</h3>
              <div class="form-group">
                <label for="writter_detail_description" class="col-sm-2 control-label">detail </label>
                <div class="col-sm-10">
                  <textarea class="form-control editors" name="writter_detail_description[]" id="textarea0" rows="10">textarea0</textarea>
                </div>
              </div>
  </div>
</div>

</div>
  • 写回答

2条回答 默认 最新

  • douci4026 2015-10-09 05:12
    关注

    try this

    setTimeout(function () { CKEDITOR.replace('editorID'); }, 150);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题