首页 > 解决方案 > CKEditor setData() 不使用模态表单

问题描述

我的网页上有两个 CKEditor 实例:第一个与其他表单输入一起用于将记录添加到引导表;另一个用于以模态形式编辑该记录。

我尝试了 setData() 的所有不同组合:

抛出错误(有或没有回调)

        var editorModal = CKEDITOR.replace( 'editRemarks', {
            customConfig: '/contest/common/js/ckeditor_config_wf.js'
        });

        editorModal.setData( [row.htmlRemarks], {
            callback: function() {
                this.checkDirty(); // true
            }
        } );

这不会引发错误,但不会设置数据

        editorModal.on( "instanceReady", function( event ){
            editorModal.setData([row.htmlRemarks]);
         });

在后一种情况下,一旦显示模式,我可以从控制台设置内容,如下所示:

editorModal.setData('<p>Hello World</p>');

由于表格最多可以包含 10 条记录,因此我需要动态更新模态表单输入(通过表格行上的编辑按钮)。我究竟做错了什么?

CKEditor v4.15.1 • 2020 年 9 月 11 日

编辑 我的主窗体使用 CKEditor 实例向条目添加注释,然后单击“添加模型条目”按钮将其添加到下表中。

在此处输入图像描述

然后,用户可以通过单击编辑图标来编辑详细信息,这会弹出一个模式表单:

在此处输入图像描述

我的配置文件中的插件列表:

config.extraPlugins = 'button,dialog,panelbutton,colorbutton,colordialog,wordcount,notification,htmlwriter,confighelper,autogrow';

它现在才起作用,因为我在编辑按钮单击上设置了实例:

if (CKEDITOR) {
    if (!editorModal) {
        editorModal = CKEDITOR.replace('editRemarks', {
customConfig: '/contest/common/js/ckeditor_config_wf.js'
        });
    }
}

...并在保存时将其销毁:

if (editorModal) {
    editorModal.destroy();
    editorModal = undefined;
}

标签: jqueryckeditor

解决方案


推荐阅读