Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"myDropzone.emit is not a function" Dropzone js

Tags:

dropzone.js

I succesfully parsed some photos from the server to repopulate a form Post. Now I need them to be displayed I have this code and with a firefox console the data is stored correctly in mockFile but when the time of pulling I got the myDrzone.emit is not a function. here is the code. (Im new to javascript)

init: function () {

$.get('/getphoto',{'key': $('[name=key]').val()},function(data){
        var files = JSON.parse(data);
        for (var i = 0; i < files.length; i++) {

            var mockFile = {
                url: files[i].url,
                size: files[i].size,
                name: files[i].name

            };
            var myDropzone = this;
            myDropzone.emit("addedfile", mockFile); //here I get the error
            myDropzone.emit("thumbnail", mockFile);
            myDropzone.emit("success", mockFile); 

            var existingFileCount = 1; // The number of files already uploaded
            myDropzone.options.maxFiles = myDropzone.options.maxFiles - existingFileCount;
        }

        });

I have the Jquery plugin set before the dropzone.js

like image 703
FerchoCarcho Avatar asked Nov 01 '25 01:11

FerchoCarcho


1 Answers

I had to move

var myDropzone = this;

just after

init: function () {

to fix the problem. As Im new to Javascript I dont really know the process of declaring the variables.

like image 177
FerchoCarcho Avatar answered Nov 02 '25 14:11

FerchoCarcho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!