简体   繁体   中英

dropzone.js increment a variable when file is uploaded

I have started to use dropzone.js and i have designed this code :

$(function() {

   var myDropzone = new Dropzone("div#mydropzone",{ url: "http://127.0.0.1/" } );

   var index = 0;

   myDropzone.on("complete", function(file) {
     index = index++;
   });

   myDropzone.on("removedfile", function(file) {     
   });

})

The index variable doesn't get incremented. Is there is a way to increment this variable?

[The "++" increment] operator increments (adds one to) its operand and returns a value. If used postfix, with operator after operand (for example, x++), then it returns the value before incrementing. If used prefix with operator before operand (for example, ++x), then it returns the value after incrementing.

Documentation here.

You are returning the value before incrementing, rather than after.

These will work:

index=++index;

OR

index++;

OR

index=index+1;

OR

index+=1;

Here's a fiddle to demonstrate: http://jsfiddle.net/ec4Uj/3/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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