简体   繁体   English

无法在CK编辑器上获取数据

[英]Data not fetch on CK Editor

I'm trying to bind data in CK Editor from database. 我正在尝试从数据库绑定CK编辑器中的数据。 But it is nor work properly, data is fetch but not display, display only when click on inspect element in Google Chrome. 但它也无法正常工作,数据已获取但无法显示,仅在单击Google Chrome中的检查元素时显示。

HTML HTML

 <textarea id="input" name="input"></textarea>

JS JS

<script>
 $(document).ready(function () {
    $("#input").ckeditor();
 });       
function BindData() {
 $("#input").val('This is CK Editor Demo');   
}
BindData();
</script>

Link Here Here链接

First, you got to wait for DOM to be ready, then you got to wait for editor to be ready, and finally you can bind your data: 首先,您必须等待DOM准备就绪,然后必须等待编辑器准备就绪,最后可以绑定数据:

// Wait for DOM to be ready.
$( document ).ready( function() {
   // Create an instance of the editor.
   $( '#input' ).ckeditor( function( textarea ) {
     // When the instance is ready, set some data.
     $( textarea ).val( 'This is CK Editor Demo!' );  
   } );
} );

Or with an external method: 或使用外部方法:

function BindData() {
  $( '#input' ).val( 'This is CK Editor Demo!' );  
}

// Wait for DOM to be ready.
$( document ).ready( function() {
   // Create an instance of the editor.
   $( '#input' ).ckeditor( function() {
     // When the instance is ready, set some data.
     BindData();
   } );
} );

Read the official guide for the new jQuery adapter (since 4.2). 阅读新版jQuery适配器的官方指南 (从4.2开始)。

You load ckeditor and after you fill the textarea. 您加载ckeditor,并在填充文本区域之后。 No way, the ckeditor is loaded. 没办法,ckeditor已加载。 An has not live update. 没有实时更新。 You must change order. 您必须更改订单。

<script>
function BindData() {
 $("#input").val('This is CK Editor Demo');   
}
BindData();

 $(document).ready(function () {
    $("#input").ckeditor();
 });       
</script>

You can use : 您可以使用 :

CKEDITOR.instances[ckeditorname].setData(yourdata)

To bind data after ckeditor instance 在ckeditor实例之后绑定数据

Try : 尝试:

<script>
 $(document).ready(function () {
    $("#input").ckeditor();
    BindData();
 });

function BindData() {
    CKEDITOR.instances["input"].setData('This is CK Editor Demo');   
}

</script>

Calling BindData() function after ckeditor init. 在ckeditor初始化之后调用BindData()函数。

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

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