简体   繁体   English

如何修复错误:Dropzone 已附加?

[英]How to fix Error: Dropzone already attached?

When I successfully upload an image, I want to run editDataImage() to retrieve the data that is on the server.当我成功上传图像时,我想运行editDataImage()来检索服务器上的数据。 But when I will display image data in the dropzone , I get an error.但是当我将在dropzone显示图像数据时,出现错误。 Please help me!请帮我!

Function Get Data Image函数获取数据图像

            editDataImage(uuid){
                var app = this;
                app.$http({
                    url: app.api_url+'/gambarpengambilcontoh/'+uuid,
                    method: 'GET',
                }).then((response)=>{
                    var app = this;
                    app.imageList = response.data.data;
                    app.editGambar();
                });
            },

Function Dropzone功能 Dropzone

            editGambar(){
                var app = this;
                Dropzone.autoDiscover = false;
                $("#edit_image").dropzone({
                    url: app.api_url+'/gambarpengambilcontoh/tambah',
                    paramName: 'gambar_ambil_contoh',
                    headers: {
                        'Authorization': 'Bearer '+localStorage.getItem('authToken'),
                        'Accept': 'Application/json',
                    },
                    maxFiles: 10,
                    maxFilesize: 10,
                    addRemoveLinks: true,
                    init: function() {
                        var myDropzone = this;
                        if (app.imageList) {
                            for (var i = 0; i < app.imageList.length; i++) {
                                var mockFile = {
                                    name: app.imageList[i].gambar_ambil_contoh,
                                    status: Dropzone.ADDED,
                                    url: app.base_url+'/assets/gambarAmbil/'+app.imageList[i].gambar_ambil_contoh,
                                };
                                myDropzone.files.push(mockFile);
                                myDropzone.emit("addedfile", mockFile);
                                myDropzone.emit("thumbnail", mockFile, app.base_url+'/assets/gambarAmbil/'+app.imageList[i].gambar_ambil_contoh);
                                myDropzone.emit("processing", mockFile);
                                myDropzone.emit("success", mockFile);
                                myDropzone.emit("complete", mockFile);
                                $('.dz-image').last().find('img').attr({width: '120px', height: '120px'});
                            }
                        }

                        this.on("removedfile", function(file){
                            $.ajax({
                                headers: {
                                    'Authorization': 'Bearer '+localStorage.getItem('authToken'),
                                    'Accept': 'Application/json',
                                },
                                url: app.api_url+'/gambarpengambilcontoh/delete',
                                type: 'DELETE',
                                data: {'gambar_ambil_contoh': file.name}
                            })
                        });

                        this.on('sending', function(file, xhr, formData) {
                            formData.append('pengambil_contoh_id', app.formData.id);
                        });

                        this.on("success", function(file) {
                            app.editDataImage(app.formData.uuid); // call back function Get Data Image
                        });

                    }
                })
            },

Error错误

Error: Dropzone already attached.

Sorry, if my question is a little confusing!对不起,如果我的问题有点混乱!

Move your Dropzone.autoDiscover = false;移动你的Dropzone.autoDiscover = false; outside of editGambar() functioneditGambar()函数之外

//Dropzone Configuration
Dropzone.autoDiscover = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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