等待TinyMCE加载

Pit*_*ger 23 jquery tinymce

我一个接一个地拥有这两行代码.

tinymce.execCommand('mceAddControl',true,'email_body');
tinyMCE.activeEditor.setContent(data.tplCustom.htmltemplate);
Run Code Online (Sandbox Code Playgroud)

第二行尝试甚至在完成之前设置内容.我认为原因是我得到"tinyMCE.activeEditor为null"错误.

有没有办法等到它加载?谢谢

Red*_*Taz 56

TinyMCE的第4版使用稍微不同的事件绑定方法.

版本3

// v3.x
tinymce.init({
    setup : function(ed) {
        ed.onInit.add(function(ed) {
            console.debug('Editor is done: ' + ed.id);
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

版本4

// v4.x
tinymce.init({
    setup: function (ed) {
        ed.on('init', function(args) {
            console.debug(args.target.id);
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

参考:http : //www.tinymce.com/wiki.php/API3: event.tinymce.Editor.onInit http://www.tinymce.com/wiki.php/Tutorial:Migration_guide_from_3.x


Cam*_*bes 11

如果您无法访问tinymce.init({...})声明(例如在WordPress中),您还可以使用addeditor事件:

  /// Fires when an editor is added to the EditorManager collection.
  tinymce.on('addeditor', function( event ) {
    var editor = event.editor;
    var $textarea = $('#' + editor.id);
    console.log($textarea.val());
  }, true );
Run Code Online (Sandbox Code Playgroud)

TinyMCE'additor'事件文档