将Tinymce与WordPress一起使用。同一页面上的多个编辑器。 tinymce.editors Array如果在文本模式下加载编辑器,则为空数

发布于 2025-02-02 17:26:42 字数 649 浏览 3 评论 0原文

我正在使用WordPress使用Tinymce。我需要它作为自定义WordPress插件的一部分。 因此,有一个包含多个Tinymce编辑器的页面,每个编辑器具有不同的ID。它们每个人都是用 wp_editor()函数。当用户执行一个操作时,例如单击按钮,我想使用tinymce.get('exampleId')。SetContent()设置特定编辑器的内容。只要在视觉模式下加载Tinymce,这种情况就可以正常工作。像有2种模式:视觉和文本。

当用户更改为文本模式时,离开页面并稍后再回来,这些Tinymce编辑器将尝试在文本模式下而不是视觉模式加载。但这是我的问题:如果这些编辑器以文本模式加载,则这些编辑不在tinymce.editors array中,并且使用tinymce.get()将导致javaScript错误,即null。如果用户切换回Visual模式,则该特定编辑器将出现在Tinymce.editors数组中。因此,用户需要将每个编辑器切换回视觉模式,以便将它们推到tinymce.editors阵列上。

目前,我只是隐藏了切换模式按钮,但是我知道是否有任何解决方案。

I'm using TinyMCE with WordPress. I need it as a part of my custom WordPress plugin.
So there is a page containing multiple TinyMCE editors, each with different ID. Each of them was created with wp_editor() function. When user performs an action like clicking the button I want to set content of the particular editor using tinymce.get("exampleID").setContent(). That works fine as long as TinyMCE was loaded in Visual Mode. Like there are 2 modes: visual and text.

When user changes to the text mode, leaves the page and come back later these TinyMCE editors will try to load in the text mode instead of visual one. But here is my problem: if these editors are loaded in text mode these are not in the tinymce.editors array and using tinymce.get() will result with javascript error saying it's null. If user switches back to visual mode, that particular editor will appear in the tinymce.editors array. So user needs to switch each of editors back to visual mode so these will be pushed to tinymce.editors array.

Currently I just hide the toggle mode buttons but I would know if there is any solution for that.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文