为什么Tinymce第二次加载失败?

Ash*_*ini 4 jquery tinymce ruby-on-rails tinymce-4

我有以下代码来渲染tinymce。之前一直好好的,不知道为什么突然就坏了。首先它完美地渲染了tinymce。第二次加载失败。第二个我发现tinymce.editors.length = 1,意味着编辑就在那里。

tinyMCE.init({
    paste_as_text: true,
    mode: 'textareas',
    plugins: ['paste link textcolor'],
    force_br_newlines: true,
    paste_remove_spans: true,
    toolbar: "undo redo | bold italic underline forecolor | link unlink",
    menubar: false,
    statusbar: false,
    browser_spellcheck: true,
    forced_root_block: "",
    setup: function (editor) {
        editor.on('init', function() {
            $('#loading_gfx').css('display', 'none'); 
        });

    }
});
Run Code Online (Sandbox Code Playgroud)

我找到的解决方案

if (tinymce.editors.length > 0) {
    tinymce.execCommand('mceFocus', true, textArea_id );       
    tinymce.execCommand('mceRemoveEditor',true, textArea_id);        
    tinymce.execCommand('mceAddEditor',true, textArea_id);
}
Run Code Online (Sandbox Code Playgroud)

但我不明白为什么它突然中断,我有最新的tiny mce版本4.2.3任何人都知道原因。

小智 8

在尝试创建重复实例之前删除现有实例:

tinymce.remove("#editor");

tinymce.init({ target: document.getElementById('editor') }); 
Run Code Online (Sandbox Code Playgroud)