将照片上传到网站时,这些照片会显示在图库中。画廊有能力移动图片。如何使在列表中移动照片时,同一张照片会更改其在数组列表中的位置,因为 照片存储在数据库中的顺序与它们在 FileList 数组中的顺序相同。
let arrPhotoList = document.getElementById('uploadgallery').files;
let oldElPhoto = arrPhotoList[evt.oldIndex];
arrPhotoList[evt.oldIndex] = arrPhotoList[evt.newIndex];
arrPhotoList[evt.newIndex] = oldElPhoto;
我尝试使用这种方法,但 FileList 不允许您以这种方式覆盖列表元素。如果突然不可能在 FileList 中进行此类操作,那么如何过滤文件数组并将其写入<input type="file" name="gallery[]" class="hidden" id="uploadgallery" accept="image/*" multiple>
创建一个空数组:
var arr = [];我们将所有上传的照片保存到创建的数组
arr中。arr我们按照需要的顺序移动照片(数组元素):arr.splice(from, 1, arr.splice(to, 1, arr[from])[0]);我们伪造数据
FormData并将其发送到服务器,例如,通过 ajax:PS谢谢你的提示。