[英]Summernote onImageUpload doesn't work when i get code content from server
当我创建一个帖子时,我的图片上传工作正常,但是回调在编辑页面上中断了
这是我的summernote配置:
$('#summernote').summernote({
focus: false,
lang: 'pt-BR',
codemirror: { // codemirror options
theme: 'monokai'
},
toolbar: [
// [groupName, [list of button]]
['font', ['style','fontname', 'fontsize' ]],
['style', ['color','bold', 'italic', 'underline', 'clear']],
['para', ['ul', 'ol', 'paragraph', 'height']],
['insert', ['picture', 'link', 'hr']],
['misc', ['codeview']]
],
callbacks: {
onImageUpload: function (files, editor, welEditable) {
console.log('oi');
for (var i = files.length - 1; i >= 0; i--) {
sendFile(files[i], this)
}
},
onMediaDelete: function ($target, editor, $editable) {
let url = $target[0].src.split('/imgs/post/')[1]
$.post({
url: `http://${window.location.hostname}:3000/remove/foto/${url}`,
cache: false,
contentType: false,
processData: false
})
$target.remove()
}
}
})
内容正确填充了编辑器,但设置后,回调将停止工作。 从服务器获取内容:
let content = String({{ data.content | dump | safe }})
if(content.length) $('#summernote').summernote('code', content)
找到了解决方案
从服务器之前获取:
let content = String({{ data.content | dump | safe }})
然后使用方法链进行初始化:
$('#summernote').summernote({
focus: false,
lang: 'pt-BR',
code: 'asdpokaposdk',
codemirror: { // codemirror options
theme: 'monokai'
},
toolbar: [
// [groupName, [list of button]]
['font', ['style','fontname', 'fontsize' ]],
['style', ['color','bold', 'italic', 'underline', 'clear']],
['para', ['ul', 'ol', 'paragraph', 'height']],
['insert', ['picture', 'link', 'hr']],
['misc', ['codeview']]
],
callbacks: {
onImageUpload: function (files, editor, welEditable) {
console.log('oi');
for (var i = files.length - 1; i >= 0; i--) {
sendFile(files[i], this)
}
},
onMediaDelete: function ($target, editor, $editable) {
let url = $target[0].src.split('/imgs/post/')[1]
$.post({
url: `http://${window.location.hostname}:3000/remove/foto/${url}`,
cache: false,
contentType: false,
processData: false
})
$target.remove()
}
}
}).summernote('code', content)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.