我有HTML:
<div class="form-group">
<textarea name="template_body">
</textarea>
</div>
<script>
CKEDITOR.replace('template_body');
</script>
和JS代码:
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);
});
但有时我的data
被加载到CKEDITOR,有时没有加载。如何在加载CKEDITOR后将数据设置为CKEDITOR?
答案 0 :(得分:2)
我认为问题在于ajax响应延迟。
尝试以下方法,
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);
});
});