是否可以组合两个 FileList 对象?

Is it possible to combine two FileList objects?

我有一个 FileList 对象,其中包含以前上传的文档。我正在尝试使用另一个函数通过使用另一个 FileList 对象将更多文件添加到此集合中,因此我需要 "append" 将辅助 FileList 对象添加到主要对象上。这怎么可能实现?

您必须先将 FileList 对象转换为数组,然后您可以简单地 concat 多个数组。

const joined = Array.from(fileListA).concat(Array.from(fileListB));

所选答案完全阐明了路径。这里也可以使用临时变量,如下所示:

 var temp = files
 files=Array.prototype.slice.call(temp).concat(Array.prototype.slice.call(event.target.files))

同样在 React 中,为了设置文件的状态,可以在 handleInputChange 函数中使用以下代码:

 var temp = this.state.files;         
 this.setState({
        files: Array.prototype.slice.call(temp).concat(Array.prototype.slice.call(event.target.files))
   })
const filesArray = [...filesList1, ...filesList2];
console.log(filesArray) // [File, File, File, File, File, ...]
var fileLists = [fileListA, fileListB];
var files = fileLists.reduce(function(a, c) {
    return Array.prototype.concat.call(Object.values(a), Object.values(c))
})