这是我已经问过的这个问题的后续:动态添加一个tinymce编辑器
我有一个带有编辑器的页面(tinyMCE)。我动态添加文本区域(添加条目按钮)。它工作正常期望它撤消我对其他 TinyMCE 所做的所有更改。如果我加载了一个带有显示“Something 40”的 tinyMCE 的页面并且我输入了“Something 40 and some stuff”,然后我单击添加一个条目,则会出现一个新的 tinymce,但第一个现在显示“Something 40”。
我使用以下代码:
<script type="text/javascript">
//<![CDATA[
tinyMCE.init({"selector":"textarea.tinymce","theme_advanced_toolbar_location":"top","theme_advanced_toolbar_align":"left","theme_advanced_statusbar_location":"bottom","theme_advanced_buttons3_add":"tablecontrols,fullscreen","toolbar":"insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image","plugins":"paste,table,fullscreen,image,code,link","dialog_type":"modal","content_css":"/assets/application.css"});
//]]>
</script>
<script>
function loadTinyMCEEditor() {
tinyMCE.init({"selector":"textarea.tinymce","theme_advanced_toolbar_location":"top","theme_advanced_toolbar_align":"left","theme_advanced_statusbar_location":"bottom","theme_advanced_buttons3_add":"tablecontrols,fullscreen","toolbar":"insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image","plugins":"paste,table,fullscreen,image,code,link","dialog_type":"modal","content_css":"/assets/application.css"});
}
</script>
两者都是添加微型 MCE 的相同选项,第一个是我想在页面显示时作为编辑器显示的 textarea,第二个是在我动态添加 textarea 时要调用的函数中。
这是我将 tinyMCE 添加到 nex textarea 的方法:
$(document).on 'nested:fieldAdded', (event) ->
loadTinyMCEEditor()
#alert "azeaze"+event.field.attr("id")
#alert "totoooot "+event.field.find('textarea').attr("id")
tinyMCE.execCommand "mceAddControl", true, event.field.find('textarea').attr("id")
如何在不删除其他 TinyMCE 字段的更改的情况下添加 tinyMCE?