ckeditor错误未捕获的TypeError:无法读取null的属性“属性”

时间:2018-12-30 00:43:11

标签: javascript jquery ckeditor text-editor

我想用ckeditor上传图像。 如果发生错误,我想从编辑器中删除图像。 但是每次遇到此错误。

Uncaught TypeError: Cannot read property 'attributes' of null
    at ckeditor.js:1275
    at CKEDITOR.htmlParser.element.forEach (ckeditor.js:313)
    at CKEDITOR.htmlParser.element.forEach (ckeditor.js:313)
    at a.<anonymous> (ckeditor.js:1274)
    at a.p (ckeditor.js:10)
    at a.<anonymous> (ckeditor.js:12)
    at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
    at CKEDITOR.htmlDataProcessor.toDataFormat (ckeditor.js:335)
    at $.getData (ckeditor.js:952)
    at $.<anonymous> (ckeditor.js:386)
每次上传图像时,它将图像存储在数组中。 并且如果新图像已上传且出现错误。与较早的图像进行比较。并发现有错误的图像。 这是我的代码。

        let oldImagesList = [];
        let newImagesList = [];

        editor.on('fileUploadResponse', function (evt) {
            let editorData = this.getData();

            let imgs = $(editorData).find('img').get();
            newImagesList=[];
            imgs.forEach(function (item) {
                newImagesList.push(item.src);
            });

            evt.stop();
            var data = evt.data,
                xhr = data.fileLoader.xhr,
                response = xhr.responseText.split('|');

            let Res = JSON.parse(response);
            console.log(evt)
            Array.prototype.diff = function(a) {
                return this.filter(function(i) {return a.indexOf(i) < 0;});
            };

            let diffs = $.unique( newImagesList.filter(x => !oldImagesList.includes(x)));
            if (Res.uploaded === 0) {
                evt.cancel();
                let wrapper = new DOMParser();
                wrapper.innerHTML = editorData;
                if (diffs.length > 0) {
                    diffs.forEach(function (item) {
                        jQuery( editor.editable().$ ).find(`img[src='${item}']`).parent('figure').remove();
                    });
                }

                editorData = this.getData();
                imgs = $(editorData).find('img').get();
                newImagesList=[];
                imgs.forEach(function (item) {
                    newImagesList.push(item.src);
                });
            }

            oldImagesList = newImagesList.slice(0);

            if (response[1]) {
                data.message = response[1];
                evt.cancel();
            } else {
                data.url = response[0];
            }
        });

谢谢。

0 个答案:

没有答案