问题描述
我正在使用
const myCanvas = documen.getElementsByTagName('canvas')
它实际上正在工作.它给我这样的东西:
that it's actually working. It returns me something like this:
images: [
0: canvas,
1: canvas,
2: canvas
]
这是一个Typescript项目,我要迭代此Array并转换每个图像以进行记录.
This is for a Typescript project, I want to iterate this Array and transform each image in order to log it.
像这样:
for (const image of myCanvas) {
console.log(canvas.toDataURL());
}
(我不使用foreach,因为它不适用于HTMLCollectionOf类型)
(I am not using foreach because it doesn't works with HTMLCollectionOf type)
我需要遍历getElementsByTagName返回我的HTMLCollection.输出为类型'HTMLCollectionOf'必须具有返回迭代器的'Symbol.iterator'方法
I need to iterate the HTMLCollection that getElementsByTagName is returning me. The output is Type 'HTMLCollectionOf' must have a 'Symbol.iterator' method that returns an iterator
推荐答案
以这种方式进行迭代,您需要这样设置compilerOptions
:
In order to iterate that way you need to set compilerOptions
like this:
"compilerOptions": {
// ...
"target": "ES6",
"lib": [
"DOM",
"DOM.Iterable",
"ES6"
]
// ...
}
这篇关于输入"HTMLCollectionOf< HTMLCanvasElement>"必须具有返回迭代器的'[Symbol.iterator]()'方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!