2012-08-02 11 views
8

Tengo algunas áreas de texto y todas ellas están con tinyMCE.setContenido de un área de texto con tinyMCE

Me gustaría establecer el contenido del área de texto específica, pero no puedo encontrar cómo.

He tryed esto:

tinyMCE.get('title').setContent(selected_article_title); 

aquí es mi área de texto:

<textarea style="width: 95%;" name="Title" id="title"></textarea> 

Y aquí mi TinyMCE init:

tinyMCE.init({ 
// General options 
mode : "specific_textareas", 
theme : "advanced", 
width: "100%", 
plugins : "pagebreak,paste,fullscreen,visualchars", 

// Theme options 
theme_advanced_buttons1 : "code,|,bold,italic,underline,|,sub,sup,|,charmap,|,fullscreen,|,bullist,numlist,|,pasteword", 
theme_advanced_buttons2 :"", 
theme_advanced_buttons3 :"", 
theme_advanced_buttons4 :"", 
theme_advanced_toolbar_location : "top", 
theme_advanced_toolbar_align : "left", 
theme_advanced_statusbar_location : "bottom", 
valid_elements : "i,sub,sup", 
invalid_elements : "p, script", 
editor_deselector : "mceOthers" 
}); 

no sé por qué esto no es trabajando, estoy usando el ejemplo del sitio web tinyMCE http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent

Respuesta

10

tengo la solución (a thans Thariama que me da algunos elementos)

Para establecer el contenido de un área de texto usando TinyMCE, que heve para rellenar el área de texto antes del inicio del TinyMCE. Además, la respuesta es la siguiente:

  1. Cree el área de texto:

    <textarea style="width: 95%;" name="Title" id="title"></textarea> 
    
  2. Establecer el contenido del área de texto:

    $('#title').html(selected_article_title); 
    
  3. Init del TinyMCE:

    tinyMCE.init({ 
    // General options 
    mode : "specific_textareas", 
    theme : "advanced", 
    width: "100%", 
    plugins : "pagebreak,paste,fullscreen,visualchars", 
    
    // Theme options 
    theme_advanced_buttons1 : "code,|,bold,italic,underline,|,sub,sup,|,charmap,|,fullscreen,|,bullist,numlist,|,pasteword", 
    theme_advanced_buttons2 :"", 
    theme_advanced_buttons3 :"", 
    theme_advanced_buttons4 :"", 
    theme_advanced_toolbar_location : "top", 
    theme_advanced_toolbar_align : "left", 
    theme_advanced_statusbar_location : "bottom", 
    valid_elements : "i,sub,sup", 
    invalid_elements : "p, script", 
    editor_deselector : "mceOthers" 
    }); 
    

¡Y listo! Disfrutar.

1

El uso de este

tinyMCE.get('title').setContent(selected_article_title); 

no va a funcionar. Establecerá el contenido de su editor.

Para establecer el elemento html editor de fuente (el área de texto), necesitará configurar directamente utilizando

$('#title').html(selected_article_title); 

Es necesario ser consciente de que su editor no es el mismo que el área de texto!

+0

Gracias @Thariama, pero esto no funciona para mí. Mi área de texto todavía está vacía. –

6

Para la versión tinymce 4,

tinymce.get('title').setContent(selected_article_title); 

funciona bien - también después de inicializar el editor.

+0

Esto funcionó para mí –

0

Si establece un contenido que contiene mso etiquetas (un contenido html generado a partir de outlook2013, que contiene una lista numerada, por ejemplo), pierde los elementos de la lista. Configurando a través de tinymce.activeEditor.setContent (foo) o configurando por primera vez el contenido textarea y luego inicializando tinymce da el mismo resultado, no podemos ver los elementos de la lista correctamente, están alineados a la izquierda. Pero si configuramos utilizando setContent(foo, { format:'raw' }), vemos los elementos de la lista correctamente. ¿Por qué?

6

creo que esto va a resolver su problema

funciona bien para TinyMCE v: 4. .

// Sets the HTML contents of the activeEditor editor 
tinyMCE.activeEditor.setContent('<span>some</span> html'); 

// Sets the raw contents of the activeEditor editor 
tinyMCE.activeEditor.setContent('<span>some</span> html', {format : 'raw'}); 

// Sets the content of a specific editor (my_editor in this example) 
tinyMCE.get('my_editor').setContent(data); 

// Sets the bbcode contents of the activeEditor editor if the bbcode plugin was added 
tinyMCE.activeEditor.setContent('[b]some[/b] html', {format : 'bbcode'}); 

el enlace para el código es TinyMCE setContent

0

Los siguientes obras con la versión tinymce 4, y no muestra el editor como un área de texto mientras está siendo arrastrado:

function initializeEditors() { 
    var editorContent = {}; 
    $("#photo-list").sortable({ 
     start: function (e, ui) { 
      $('.attachment-info').each(function() { 
       var id = $(this).attr('id'); 
       editorContent[id] = tinyMCE.get(id).getContent(); 
      }); 
     }, 
     stop: function (e, ui) { 
      $('.attachment-info').each(function() { 
       var id = $(this).attr('id'); 
       tinymce.execCommand('mceRemoveEditor', false, id); 
       tinymce.execCommand('mceAddEditor', true, id); 
       tinyMCE.get(id).setContent(editorContent[id]); 
      }); 
     } 
    }); 
} 
0
$('#title').html(selected_article_title); 

Asegúrese de que selected_article_title no contenga ninguna etiqueta html.

Cuestiones relacionadas