1

我无法让我的 CKEditor 正常工作。

我正在使用 Jquery 插入我的实例。并为编辑器设置了我自己的Ajax保存功能。

我的实例总是插入得很好。编辑器按应有的方式出现,并且似乎可以正常工作。但是:事实证明,在我插入实例时 2. - textarea 没有被更新 - 因此没有更新的数据发送到 Ajaxcall。它发送旧数据。

发送到 ajax 调用后,我销毁了我的实例:CKEDITOR.instances[currentInstance].destroy(); 而且编辑器似乎每次都被正确销毁。OnClick 然后我重新插入编辑器(相同的实例名称。我在销毁实例时也删除了文本区域,然后在重新插入实例时重新插入文本区域。相同的文本区域名称)。

谁能告诉我为什么我可以一次又一次地插入实例,但编辑器只在第一次更新文本区域?

我试过了:

for ( var instance in CKEDITOR.instances ) {
            CKEDITOR.instances[instance].updateElement(); }

插入保存功能 - 就在 ajaxcall 之前。但是还是没有更新。

这是实例的构建。通过 Jquery,我将其插入为 html() :

<script type="text/javascript">
    CKEDITOR.replace('tekstindhold233',
    { height:'250px',width:'575px' });
</script>

这是保存功能:

CKEDITOR.plugins.add('popwebsave',
{
init: function(editor)
{
var pluginName = 'popwebsave';


editor.addCommand( pluginName,
{
exec : function( editor )
{

for ( var i in CKEDITOR.instances ){
   var currentInstance = i;
   break;
}
for ( var instance in CKEDITOR.instances ) {
            CKEDITOR.instances[instance].updateElement(); }

var sprog = $('#lan_holder').text();
var vis = $('#vis_holder').text();
var pageId = $('#pageId_holder').text();
var tekstIndhold = CKEDITOR.instances[currentInstance].getData();
var tekstIndholdBox = currentInstance.replace('tekstindhold','');
var contentOrden = $('#content_orden' + tekstIndholdBox).text();
var dataString = 'lan=' + sprog + '&tekstindhold=' + tekstIndhold + '&eid=' + tekstIndholdBox + '&vis=' + vis + '&id=' + pageId + '&contentOrden=' + contentOrden;

$("#tekstindhold_box" + tekstIndholdBox).animate({ 
    opacity: 0  
        } , { 
    duration: 500,  
    complete: function() {
    $("#textarea_box" + tekstIndholdBox).text('');

$.ajax({
type: "POST",
url: "includes/JQ_opdater_tekst.php",
data: dataString,
dataType: "json",
cache: false,
success: function(databack){  
$("#textarea_box" + tekstIndholdBox).animate({
        height: 100
      }, 500, function() {
        $("#tekstindhold_box" + tekstIndholdBox).html(databack.tekstindhold_db);
        $("#tekstindhold_box" + tekstIndholdBox).animate({
        opacity: 1
      }, 500, function() {

CKEDITOR.instances[currentInstance].destroy();

        });
});

    }

});


        }
    });

},
canUndo : true
});

/*
editor.addCommand(pluginName, 
new CKEDITOR.dialogCommand(pluginName)

);
*/

editor.ui.addButton('Popwebsave',
{
label: 'Gem',
command: pluginName,
className : 'cke_button_save'
});
}
});
4

1 回答 1

1

没关系!我想到了。事实证明,该实例需要存在于 DOM 中,在 destroy() 上,我切换了事件的顺序,以便首先发生 destroy(),然后删除了 textarea。现在工作得很好。

于 2012-07-17T09:16:46.110 回答