tinyMCE.get ("content") не определено - PullRequest
4 голосов
/ 24 ноября 2011

Я получаю это сообщение: tinyMCE.get("message_data_" + msg_id) is undefined на Firebug после Я нажимаю на кнопку, чтобы отправить форму.

msg_id определено , я проверил. message_data_ также определено. Функция tinyMCE.get не по какой-то причине.

Ответы [ 3 ]

4 голосов
/ 24 ноября 2011

Если вы используете один экземпляр редактора, вы можете использовать tinymce.editors[0] вместо tinyMCE.get("message_data_" + msg_id).

1 голос
/ 28 января 2015

Если у вас нет контроля над методом инициализации TinyMCE, вы можете воспользоваться этим решением. В основном это добавляет запасной вариант, если TinyMCE не инициализирован.

jQuery(document).ready(function($) {

    function myCustomSetContent( id, content ) {
        // Check if TinyMCE is defined or not.
        if( typeof tinymce != "undefined" ) {
            var editor = tinymce.get( id );
            // Check if TinyMCE is initialized properly or not.
            if( editor && editor instanceof tinymce.Editor ) {
                editor.setContent( text );
                editor.save( { no_events: true } );
            } else {
                // Fallback
                // If TinyMCE is not initialized then directly set the value in textarea.
                //TinyMCE will take up this value when it gets initialized.
                jQuery( '#'+id ).val( text );
            }
            return true;
        }
        return false;
    }

    function myCustomGetContent( id ) {
        // Check if TinyMCE is defined or not.
        if( typeof tinymce != "undefined" ) {
            var editor = tinymce.get( id );
            // Check if TinyMCE is initialized properly or not.
            if( editor && editor instanceof tinymce.Editor ) {
                return editor.getContent();
            } else {
                // Fallback
                // If TinyMCE is not initialized then directly set the value in textarea.
                // TinyMCE will take up this value when it gets initialized.
                return jQuery( '#'+id ).val();
            }
        }
        return '';
    }

    $(".class-to-update-content").on("click", function(e) {
        myCustomSetContent( "tinymce-editor-id", "New Content in Editor" );
    });

    $(".class-to-get-content").on("click", function(e) {
        $("div.class-to-display-content").html( myCustomGetContent( "tinymce-editor-id" ) );
    });
});

Ссылка: http://blog.incognitech.in/tinymce-undefined-issue/

0 голосов
/ 17 ноября 2013

если вы используете в редакторе несколько редакторов, вы можете создать функцию и получить ее значение т.е.

// Declare a function to get editor value
function tinyMca_text(field_id) {

 if ( jQuery("#"+field_id+":hidden").length > 0)
 {
 return tinyMCE.get(field_id).getContent();
 }
 else
 {
  return jQuery('#'+field_id).val();
 }

}

// show that value

console.log(tinyMca_text('field'));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...