简体   繁体   中英

How to set data to CKEDITOR after CKEDITOR load?

I have HTML:

<div class="form-group">
    <textarea name="template_body">
    </textarea>
</div>

<script>
    CKEDITOR.replace('template_body');
</script>

And JS-code:

var editor = CKEDITOR.instances["template_body"];
var requestGetValue = $http({
    method: "get",
    url: "/getValue",
    dataType: 'json',
    contentType: 'application/json',
    mimeType: 'application/json'
});
requestGetValue.success(function (data) {
        editor.setData(data);
});

But sometimes my data was loaded to CKEDITOR, and sometimes wasn't loaded. How to set data to CKEDITOR after load CKEDITOR?

I assume the problem is with the ajax response delay.

Try the following,

var editor = CKEDITOR.replace( 'template_body' );

editor.on( 'contentDom', function(){
 var requestGetValue = $http({
    method: "get",
    url: "/getValue",
    dataType: 'json',
    contentType: 'application/json',
    mimeType: 'application/json'
});
requestGetValue.success(function (data) {
        editor.setData(data);
});

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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