TinyMCE JQuery插件并不总是更新textareas

Kei*_*ith 4 jquery tinymce jquery-plugins

我们有一个有很多textareas的表单(在某些情况下,多达20个).这些textareas中的每一个都通过TinyMCE jquery插件转换为所见即所得的编辑器,如下所示:

var tinymceoptions = {
    script_url: '/Scripts/tiny_mce/tiny_mce.js',
    theme: "advanced",
    mode: "textareas",
    elements: "text,html1",
    theme_advanced_buttons1: "bold,italic,underline,formatselect,separator,image,insertfile,separator,blockquote,bullist,numlist,separator,undo,redo,separator,link,unlink,separator,code,insertimage",
    theme_advanced_buttons2: "",
    theme_advanced_buttons3: "",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_blockformats: "h1,h2,h3,p",
    width: '100%',
    content_css: Settings["tiny_mce_css"],
    plugins: "advimage,advlink,autoresize,inlinepopups,imagemanager,paste",
    relative_urls: false,
    forced_root_block: false
};

$('textarea.editor').tinymce(tinymceoptions);
Run Code Online (Sandbox Code Playgroud)

我们遇到的问题是大约95%的时间,textareas没有在表单POST之前使用所见即所得内容进行更新.我们甚至尝试通过循环遍历每个mce编辑器并在提交表单之前调用save()方法来强制保存:

    $('textarea.editor').each(function () {
        $(this).tinymce().save();
    });
Run Code Online (Sandbox Code Playgroud)

用Fiddler再次检查POST,我发现textarea仍未使用适当的值进行更新.

有没有人知道可能导致这种情况的原因?

UPDATE

更重要的是...有趣......我添加了以下回调,我得到了奇怪的结果.当表单发布WORKS时,每次按一个键时getContent()的值都会改变.当表单帖子不工作时,无论我输入多少内容,getContent都会不断返回初始值:

setup: function (ed) {
    ed.onSaveContent.add(function (ed) {
        console.debug('save content: ' + $(this).tinymce().getContent());
    });
    ed.onKeyPress.add(function (ed, e) {
        console.debug('Editor contents was modified. Contents: ' + $(this).tinymce().getContent());
    });
}
Run Code Online (Sandbox Code Playgroud)

更新2

越来越近?我发现清除缓存似乎暂时"修复"了问题.后续访问将显示损坏的行为.

Kei*_*ith 7

我确定滥用head.js导致了这个问题.我们在head.ready()上通过ajax加载一些项目,并在$ .ready()期间应用tinyMCE.将$ .ready()更改为head.ready()解决了这个问题.