我有一个拖拽n下拉框,在那里我显示图像预览(用于排序和旋转),并将它们上传到服务器。如果我第一次丢弃一个或多个图像,一切都是正常的。但是如果我把新的图片放在现有的图片上(比如我添加了2张新图片,我已经有了3张来自之前的图片),在预览中我确实看到了所有的图片(总共5张),但当我上传到服务器时,只有最后2张真正上传了。
以下是我使用的Javascript代码的一部分:
form.addEventListener( 'drop', function( e )
{
droppedFiles = e.dataTransfer.files; // the files that were dropped
showFiles( droppedFiles ); // the fx that shows the previews
});
.....
var ajaxData = new FormData( form );
if( droppedFiles ) {
Array.prototype.forEach.call( droppedFiles, function( file )
{
ajaxData.append( input.getAttribute( 'name' ), file );
});
}
发布于 2020-10-24 00:56:24
您需要保留droppedFiles之前的值,使用扩展运算符:
droppedFiles = [... droppedFiles, e.dataTransfer.files]; // the files that were dropped
showFiles( droppedFiles ); // the fx that shows the previews
https://stackoverflow.com/questions/64502494
复制相似问题