Javascript javascript从文件列表创建文件列表对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38449440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:30:30  来源:igfitidea点击:

javascript create file list object from list of files

javascript

提问by aryan

I have a list of file object like:

我有一个文件对象列表,如:

var files = [File, File, File]

I want to convert it to something like:

我想把它转换成类似的东西:

I have a file field where I want to map my filesas FileListobject.

我有一个文件字段,我想将我filesFileList对象映射到其中。

var uploading_files = {}
files.forEach(function(file, key) {
    uploading_files[key] = file

})
var uploader = document.getElementById('uploader')
uploader.files = uploading_files

console.log(uploader.files)

But It does not give me FileListobject ? How can I create a file list objecdt ? Thanks in advance..

但它不给我FileList对象?如何创建文件列表对象?提前致谢..

回答by Timur Gilauri

The FileList object is "read-only" and has no implementation of its constructor.

FileList 对象是“只读的”并且没有其构造函数的实现。

Visit this page: FileList On MDN

访问此页面:MDN 上的 FileList