简体   繁体   English

按类获取TinyMCE实例

[英]Get TinyMCE instance by class

I have a form with multiple TinyMCE instance. 我有一个包含多个TinyMCE实例的表单。 I created the TextArea controls dynamically using a Repeater control - They all have the same ID,but I gave each one a different class. 我使用Repeater控件动态创建了TextArea控件 - 它们都具有相同的ID,但我为每个控件赋予了不同的类。 I assigned each of the TextArea controls a TinyMCE instance using the editor_selector : option in the TinyMCE Init function. 我使用TinyMCE Init函数中的editor_selector:选项为每个TextArea控件分配了一个TinyMCE实例。

tinyMCE.init({ mode : 'textareas',theme : 'simple',editor_selector : 'upperBlock',directionality : 'rtl'});  tinyMCE.init({ mode : 'textareas',theme : 'simple',editor_selector : 'middleBlock',directionality : 'rtl'});

I want to refer to a specific TinyMCE instance in a JS function and get its content. 我想在JS函数中引用一个特定的TinyMCE实例并获取其内容。 In the case when each TextArea control has a different id that could by done by using : 在每个TextArea控件具有不同的id的情况下,可以通过使用:

tinyMCE.get('IdOfYourTextBoxWithTheTinyMCEContent').getContent()

Is there a way to get ref to a specific TinyMCE instance content by the class assigned to it in the editor_selector option of the TinyMCE Init function ? 有没有办法通过 TinyMCE Init函数的editor_selector选项中分配给它的类获取特定的TinyMCE实例内容

Thanks 谢谢

This can't be done with native TinyMCE methods. 使用本机TinyMCE方法无法做到这一点。 You have to loop for yourself, like eg (untested) 你必须为自己循环,例如(未经测试)

for (edId in tinymce.editors) {
        if (tinymce.editors[edId].settings.editor_selector == 'upperBlock') {
        // editor found - do something
    }
}

You are doing it wrong. 你做错了。 It is not allowed in HTML to have more elements with the same ID. HTML中不允许具有更多具有相同ID的元素。 Give them the same class and diffirent IDs. 给他们相同的类和不同的ID。

If you want to retrieve the editor by class, you have to set this properties first to the editor. 如果要按类检索编辑器,则必须首先将此属性设置为编辑器。

tinymceOptions: {
                  mode: 'specific_textareas',
                  editor_selector: "yourClassName"
                }

then, your textarea would be like: 那么,你的textarea就像:

<textarea class="yourClassName"></textarea>

and then, you can iterate between all the editors you have like 然后,您可以在所有您喜欢的编辑器之间进行迭代

    tinymce.editors.forEach(function(editor) {
        if (editor.settings.editor_selector === 'yourClassName') {
        // do what you want!
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM