CKEditor instance already exists

前端 未结 30 3543
刺人心
刺人心 2020-11-27 11:24

I am using jquery dialogs to present forms (fetched via AJAX). On some forms I am using a CKEditor for the textareas. The editor displays fine on the first load.

Whe

30条回答
  •  半阙折子戏
    2020-11-27 11:53

    Perhaps this will help you out - I've done something similar using jquery, except I'm loading up an unknown number of ckeditor objects. It took my a while to stumble onto this - it's not clear in the documentation.

    function loadEditors() {
        var $editors = $("textarea.ckeditor");
        if ($editors.length) {
            $editors.each(function() {
                var editorID = $(this).attr("id");
                var instance = CKEDITOR.instances[editorID];
                if (instance) { instance.destroy(true); }
                CKEDITOR.replace(editorID);
            });
        }
    }
    

    And here is what I run to get the content from the editors:

        var $editors = $("textarea.ckeditor");
        if ($editors.length) {
            $editors.each(function() {
                var instance = CKEDITOR.instances[$(this).attr("id")];
                if (instance) { $(this).val(instance.getData()); }
            });
        }
    

    UPDATE: I've changed my answer to use the correct method - which is .destroy(). .remove() is meant to be internal, and was improperly documented at one point.

提交回复
热议问题