简体   繁体   English

在AJAX加载的DIV中重新初始化后,TinyMCE消失

[英]TinyMCE disappears after reinitialization in AJAX loaded DIV

I have gotten a lot further in the mean time. 我在平均时间里得到了更多。 There is however an issue I am still having. 然而,我仍然有一个问题。

The situation is like this : 情况是这样的:

I have a div with multiple textareas that are being loaded with an JQuery AJAX call. 我有一个带有多个textareas的div,它们正在加载JQuery AJAX调用。

The initial initialization works great using the following code : 初始初始化使用以下代码很好:

function InitializeTinyMCE() {

/// This can also be positioned outside a function in the document ready section
$.get("[@appbase]sereneadmin/pages/?SetAjaxCall=editor&page=[@editparam]", function (EditorHTML) {
    $("#SerenePageEditors").html(EditorHTML).find('.EditorField').tinymce({
        script_url: '[@appbase]script/tinymce/js/tinymce/tinymce.jquery.min.js',
        plugins: [
            "advlist autolink lists link image charmap print preview hr anchor pagebreak",
            "searchreplace wordcount visualblocks visualchars code fullscreen",
            "insertdatetime media nonbreaking save table contextmenu directionality",
            "emoticons template paste textcolor colorpicker textpattern imagetools"
        ],

        content_css: '[@appbase]app/template/css/bootstrap.min.css, [@appbase]app/template/css/div.highlighting.css'    // includes both css files in header

    });
    tinyMCE.execCommand('mceRemoveEditor', true, '#WysyWig');
    tinyMCE.execCommand('mceAddEditor', false, '#WysyWig');
});


}

But after adding another extra editor by an onclick the AJAX call gets performed perfectly and the editor gets added in the database and almost everything runs fine... except... The TinyMCE editors disappear. 但是在通过onclick添加另一个额外的编辑器后,AJAX调用得到了完美的执行,编辑器被添加到数据库中,几乎所有内容都运行良好......除了...... TinyMCE编辑器消失了。

I have done some searching and the first thing I found out that I did not do was removing the editor. 我做了一些搜索,我发现的第一件事我没有删除编辑器。 Because this needs to be done before reinitializing it. 因为这需要在重新初始化之前完成。

So I added : 所以我补充说:

    tinyMCE.execCommand('mceRemoveEditor', true, '#WysyWig');

Unfortunately this did not make any difference. 不幸的是,这没有任何区别。 So possibly I am using it wrong. 所以我可能错了。

I am using TinyMCE 4.0 我正在使用TinyMCE 4.0

I hope someone sees my error and we can continue the Journey. 我希望有人看到我的错误,我们可以继续旅程。 TIAD!! TIAD!

PS The [@appbase] is being replaced by PHP to display the absolute path to the script. PS [@appbase]正在被PHP取代,以显示脚本的绝对路径。 :-) :-)

You should remove the editors before adding the new ones... if I read your code right, you are trying to remove editors right after having created them. 您应该在添加新编辑器之前删除编辑器...如果我正确地阅读了您的代码,那么您正在尝试在创建编辑器之后立即删除编辑器。

Since .get() is asynchronous, the removal might happen before they are created, but that's not what we'd be aiming for. 由于.get()是异步的,因此删除可能在创建之前发生,但这不是我们的目标。

I'd start by removing any editors from within the #SerenePageEditors before replacing the HTML content. 我首先从#SerenePageEditors中删除任何编辑器,然后再替换HTML内容。 Probably with a call that looks like the following: 可能有一个看起来如下的调用:

tinymce.remove('#SerenePageEditors .EditorField');

Applied on your code, it would look like this: 应用于您的代码,它看起来像这样:

function InitializeTinyMCE() {
    /// This can also be positioned outside a function in the document ready section
    $.get("[@appbase]sereneadmin/pages/?SetAjaxCall=editor&page=[@editparam]", function (EditorHTML) {

        tinymce.remove('#SerenePageEditors .EditorField');

        $("#SerenePageEditors").html(EditorHTML).find('.EditorField').tinymce({
            script_url: '[@appbase]script/tinymce/js/tinymce/tinymce.jquery.min.js',
            plugins: [
                "advlist autolink lists link image charmap print preview hr anchor pagebreak",
                "searchreplace wordcount visualblocks visualchars code fullscreen",
                "insertdatetime media nonbreaking save table contextmenu directionality",
                "emoticons template paste textcolor colorpicker textpattern imagetools"
            ],

            content_css: '[@appbase]app/template/css/bootstrap.min.css, [@appbase]app/template/css/div.highlighting.css'    // includes both css files in header

        });
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM