2012-08-02 22 views
8

Ho alcune aree di testo e tutte sono con tinyMCE.setContent di una textarea con tinyMCE

Vorrei impostare il contenuto della specifica area di testo, ma non riesco a trovare il modo.

Ho provato questo:

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

qui è la mia area di testo:

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

E qui il mio 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" 
}); 

non so perché questo non è lavorando, sto usando l'esempio dal sito Web tinyMCE http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent

risposta

10

ho la soluzione (thans a Thariama che mi dà alcuni elementi)

Per impostare il contenuto di una textarea usando TinyMCE, abbiamo heve di compilare textarea prima di init il TinyMCE. Inoltre, la risposta è la seguente:

  1. Creare textarea:

    <textarea style="width: 95%;" name="Title" id="title"></textarea> 
    
  2. Impostare il contenuto del textarea:

    $('#title').html(selected_article_title); 
    
  3. Init il 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" 
    }); 
    

Ed è fatta! Godere.

1

Usando questo

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

non funzionerà. Imposterà il contenuto del tuo editor.

Per impostare l'elemento HTML Editor sorgente (textarea) è necessario impostarla direttamente utilizzando

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

È necessario essere consapevoli del fatto che il vostro editor non è la stessa come il textarea!

+0

Grazie @Thariama, ma questo non funziona per me. La mia textarea è ancora vuota. –

6

Per TinyMCE versione 4,

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

funziona bene - anche dopo aver inizializzato l'editor.

+0

Questo ha funzionato per me –

0

Se si imposta un contenuto che contiene mso tag, (un contenuto html generato da outlook2013, che contiene un elenco numerato per esempio), si perdono gli elementi dell'elenco. Impostazione tramite tinymce.activeEditor.setContent (foo) o prima impostazione del contenuto dell'area di testo e quindi di inizializzazione dello stagno dà lo stesso risultato, non è possibile vedere gli elementi dell'elenco correttamente, sono allineati a sinistra. Ma se impostiamo usando setContent(foo, { format:'raw' }), vediamo gli elementi della lista correttamente. Perché?

6

penso che questo risolverà il vostro problema

tutto funziona bene per 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'}); 

il link per il codice è TinyMCE setContent

0

le seguenti opere con TinyMCE versione 4, e non mostra l'editor come una textarea mentre viene trascinato:

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); 

Assicurati che selected_article_title non contenga tag html.