TinyMCE onSaveContent 发生多次

发布于 2024-12-24 19:15:16 字数 1215 浏览 2 评论 0原文

好吧,我觉得经过几个小时的研究和详尽的故障排除后,我已经完成了尽职调查,可以在这里寻求帮助。

我在一个页面上有多个 TinyMCE 编辑器实例。这是初始化代码:

 $('.simpletinymce').tinymce({
    // Location of TinyMCE script
    script_url : '/tm/tiny_mce.js',

    // General options
    theme : "advanced",
    plugins : "save",

    // Theme options
    theme_advanced_buttons1 : "save,cancel,newdocument,
    |,bold,italic,underline,strikethrough,
    |,cut,copy,paste,pastetext,pasteword,|,undo,redo,|,bullist,numlist",

    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",

    submit_patch:false,

    //Callback function to be executed upon saving
    setup : function(ed) {
          ed.onSaveContent.add(function(ed, o) {

          // code to execute
              alert("Your changes have been saved!");

          });
    }
)};

我遇到的问题是,当单击其中任何一个表单上的“保存”按钮时,我得到“您的更改已保存!”对页面上的每个编辑器发出警报。

两个编辑,两个警报。三个编辑器、三个警报(等等...)

特别令人困惑的是,如果我将初始化从当前类更改

$('.simpletinymce') 

为每个实例的单独 ID 引用...

$('#Instance1')
$('#Instance2')
$('#Instance3')
(etc.)

我会得到相同的结果。页面上每个 TinyMCE 实例的警报。

有没有人以前遇到过这个问题,或者知道如何解决这个问题?

如果我再扯掉更多的头发,我将不得不向下移动到眉毛:-(

Okay, I feel like after a few hours of research and exhaustive troubleshooting I've done my due diligence and can ask for help here.

I have multiple TinyMCE Editor instances on a page. Here's the initialization code:

 $('.simpletinymce').tinymce({
    // Location of TinyMCE script
    script_url : '/tm/tiny_mce.js',

    // General options
    theme : "advanced",
    plugins : "save",

    // Theme options
    theme_advanced_buttons1 : "save,cancel,newdocument,
    |,bold,italic,underline,strikethrough,
    |,cut,copy,paste,pastetext,pasteword,|,undo,redo,|,bullist,numlist",

    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",

    submit_patch:false,

    //Callback function to be executed upon saving
    setup : function(ed) {
          ed.onSaveContent.add(function(ed, o) {

          // code to execute
              alert("Your changes have been saved!");

          });
    }
)};

The problem I am having is that, when a Save button is clicked on any one of these forms, I get that "Your changes have been saved!" alert for every single editor on the page.

Two editors, two alerts. Three editors, three alerts (etc...)

What's particularly confusing is that if I change the initialization from the current class

$('.simpletinymce') 

...to an individual ID reference for each instance...

$('#Instance1')
$('#Instance2')
$('#Instance3')
(etc.)

...I get the same results. An alert for every TinyMCE instance on the page.

Has anyone run into this before, or know how to resolve this?

If I rip out any more hair I'm going to have to move down to my eye-brows :-(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情稳全场 2024-12-31 19:15:16

如果您调用triggerSave(),所有tinymce实例上的save都会被调用。
您想要的是在您选择的编辑器实例上调用 save

If you call triggerSave() save on all tinymce instance will be called.
What you want is to call save on the editor instance of your choice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文