我有一个 FileList 对象,其中包含以前上传的文档。我正在尝试使用另一个函数通过使用另一个 FileList 对象将更多文件添加到此集合中,因此我需要将辅助 FileList 对象“附加”到主要对象上。怎么可能做到这一点?
问问题
5231 次
4 回答
16
您必须首先将FileList
对象转换为数组,之后您可以简单地转换concat
多个数组。
const joined = Array.from(fileListA).concat(Array.from(fileListB));
于 2015-05-07T21:06:39.177 回答
1
const filesArray = [...filesList1, ...filesList2];
console.log(filesArray) // [File, File, File, File, File, ...]
于 2020-08-21T12:08:04.743 回答
0
选定的答案完全阐明了路径。这里也可以使用临时变量,如下所示:
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))
})
于 2020-03-07T19:50:01.130 回答
-1
var fileLists = [fileListA, fileListB];
var files = fileLists.reduce(function(a, c) {
return Array.prototype.concat.call(Object.values(a), Object.values(c))
})
于 2020-12-23T23:54:47.290 回答