当我从服务器获取代码内容时,Summernote onImageUpload 不起作用

Summernote onImageUpload doesn't work when i get code content from server

当我创建 post 时,我的图片上传工作正常,但回调在编辑页面上出现问题

这是我的 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)