Tinymce 5不会将现有内容加载到编辑器中,但是代码在代码视图中存在



我正在将Tinymce升级到5.x版本,并遇到了一些兼容性问题。尽管4.x工作,但我需要更改几个自定义按钮,这主要是有效的。如果我将文本添加到编辑器中,然后单击"保存",它可以在一组页面上工作。在另一个页面上,我似乎无法将当前内容输入编辑器,但是代码视图显示了代码。如果我然后将该代码粘贴到测试站点(Fresh Antern tiny5(中并保存到代码视图中,则可以在编辑器中显示。

我正在使用

formJson['DESCRIPTION'] = $('iframe').contents().find('body').html();

填充Div-哦,是的,我正在使用DIV作为选择器。在这种情况下

$('.tox-edit-area').html($('iframe').contents().find('body').html()).show();

从我的Tinymce init()函数中显示,该功能显示了编辑器中的内容,但它们是可读的 - 似乎是。

控制台中没有显示错误。

有人可以分享任何智慧吗?谢谢!

update

// selector is passed into the function
var html = $(selector).html();//this is successful
tinymce.init({
    selector: selector,
    setup: function(editor) {
        editor.setMode('design');
        editor.setContent(html);//this does not load the code in design mode
        alert(html);// this alerts the expected code
    },

/// could any of this additional code below be causing an issue in tiny5?
    invalid_styles: {
        '*': 'font-size,font-family', // Global invalid styles
        'a': 'background' // Link specific invalid styles
    },
    valid_styles: {
        '*': 'border,font-size',
        'div': 'width,height'
    },
    font_formats: 'Arial=arial, helvetica, sans-serif;',
    toolbar: toolbtns,
    plugins: 'code table lists',
    //~ image_advtab: true,
    menubar: false,
    statusbar: false,
    //~ force_p_newlines : false,
    //~ force_br_newlines : true,
    //~ forced_root_block : '',
    width: '100%',
    height: '500px',
    relative_urls: false,
    content_css: "/include/css/bootstrap.css",
    images_dataimg_filter: function(img) {
        return img.hasAttribute('internal-blob');
    },
});

我在做什么错?:p

您正在使用单个选择器将内容加载,也可以作为替换的目标元素。我无法重现您的失败,但是在您的情况下,setContent是不必要的,并且可以解决此问题。如果目标元素包含您的内容,则无需手动设置内容;Tinymce会为您做到这一点。

这是使用setContent使用您的代码评论的示例:

http://fiddle.tinymce.com/qggaab

如果您试图将内容加载到编辑器中,我将在以下内容遵循编辑器的设计/API时进行以下操作。

  1. init()编辑器之前,将内容加载到<div><textarea>中。
  2. 使用setContent() API初始化了Tinymce后将数据加载到Tinymce中。

您似乎依靠编辑器用来与编辑器进行交互的基础HTML结构,并且(如您所见(不保证随着时间的流逝而保持相同。

注意: 如果您要更新基础元素(<div><textarea>(,此前编辑器初始化的Tinymce看不到该更新。很难判断这是您是否存在的问题的一部分,尽管内容存在于基础<div><textarea>中。

我还会注意,Tinymce具有可读模式配置选项:

https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#setmode

...您可以用来启用或禁用其可读模式。

最新更新