Javascript 无法构造';水滴';:提供的第一个参数为null,或者是无效的数组对象。

Javascript 无法构造';水滴';:提供的第一个参数为null,或者是无效的数组对象。,javascript,jquery,file-io,Javascript,Jquery,File Io,我今天开始使用filesaver.js。我创建了以下函数: function saving(){ var blob = new Blob(final_transformation, {type: "text/plain;charset=utf-8"}); saveAs(blob, "hello world.txt"); } 但当我调用该函数时,我得到“构造'Blob'失败”:提供的第一个参数要么为null,要么是无效的数组对象。” 有什么想法吗?既然你不想告诉我们什么是最终的转换,我们

我今天开始使用filesaver.js。我创建了以下函数:

function saving(){
    var blob = new Blob(final_transformation, {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");
}
但当我调用该函数时,我得到“构造'Blob'失败”:提供的第一个参数要么为null,要么是无效的数组对象。”
有什么想法吗?

既然你不想告诉我们什么是
最终的转换,我们就得毫无背景地猜测了。试试这个:

function saving(){
    var blob = new Blob([final_transformation], {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");
}

我也犯了同样的错误

请参阅以下位置的Blob构造函数文档:

array
是一个
ArrayBuffer
ArrayBufferView
Blob
DOMString
对象的
数组
,或任何此类对象的组合,它们将被放入
Blob

因此,
newblob
的第一个参数非常具体,它只能是一个包含几种特定类型对象的数组。常规字符串对我不起作用,但它可以:

> new Blob( [ new TextEncoder().encode( 'some text' ) ], { type: 'text/plain' } )
< Blob {size: 9, type: "text/plain"}
>新Blob([new textcoder().encode('some text')],{type:'text/plain'})
console.log(最终转换)变量不是问题所在。我得到了我想要的结果您得到了想要的结果,但您有一个错误,这将是第一个参数。请尝试此变量a=new Blob([”
> new Blob( [ new TextEncoder().encode( 'some text' ) ], { type: 'text/plain' } )
< Blob {size: 9, type: "text/plain"}