我有这两行代码,依次排列。
tinymce.execCommand('mceAddControl',true,'email_body');
tinyMCE.activeEditor.setContent(data.tplCustom.htmltemplate);
第二行尝试在tinymce完成之前设置内容。我认为这就是我收到“tinyMCE.activeEditor为空”的错误的原因。
有没有办法等待直到它加载完成?谢谢
TinyMCE的第四个版本使用了略微不同的事件绑定方法。
版本3
// v3.x
tinymce.init({
setup : function(ed) {
ed.onInit.add(function(ed) {
console.debug('Editor is done: ' + ed.id);
});
}
});
版本4
// v4.x
tinymce.init({
setup: function (ed) {
ed.on('init', function(args) {
console.debug(args.target.id);
});
}
});
参考资料: http://www.tinymce.com/wiki.php/API3:event.tinymce.Editor.onInit http://www.tinymce.com/wiki.php/Tutorial:Migration_guide_from_3.x
如果您无法访问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 );