在实施CKEDITOR时,通过id查找textarea不再有效

我有一个信息表,允许用户编辑它。 在一个单元格中,有文本信息。 如果用户单击该单元格,则会出现一个bootstrap模式,其中包含一个包含从数据库中检索的当前文本的textarea。

这是表格的一部分:

 @foreach($events as $event)  @endforeach 
Event Notes
{{$event->Event}}
id}}">{{$event->notes}}

这是javascript启动模式的一部分:

 $('[id^="notes"]').on("click", function(){ var input_id = $(this).attr('id'); var previousValue = $('#'+input_id).html(); console.log('clicked! The current notes are: '+previousValue); var result = input_id.split('-'); var notes_id = result[1]; console.log('The event id selected is: '+notes_id); /*Open a modal*/ $('#modal-notes').modal('show'); $('#modal-notes').on('shown.bs.modal', function() { console.log('Modal has been opened.'); $(this).find('#observations').text(previousValue); }); }); 

模态如下所示:

  

文本显示在textarea中。 但是,如果我实现CKEDITOR,则不再显示该文本。 我只看到textarea空了。

 CKEDITOR.replace('observations'); 

直到这里,CKEDITOR工作正常,但现在textarea是空的。 当我在没有CKEDITOR的情况下检查textarea元素时,我看到textarea id确实是#observations。 但是,对于CKEDITOR,我再也看不到id了。

可能的解决方案

我刚刚在这里找到你可以将文本设置为CKEDITOR textarea,如下所示:

 CKEDITOR.instances.observaciones.setData( '

This is the editor data.

' );

好的,我找到了解决方案。 我希望这可以在不久的将来帮助其他人:

我刚打开模态时添加了以下代码:

 /*Open a modal*/ $('#modal-notes').modal('show'); $('#modal-notes').on('shown.bs.modal', function() { console.log('Modal has been opened.'); $(this).find('#observations').text(previousValue); }); CKEDITOR.replace('observations'); CKEDITOR.instances.observations.setData(previousValue); 

就是这样。

单击多个模态时我遇到了另一个问题。 解决方案在这里 。