我在指令中有一个映射显示错误代码 TS2488 Type 'HTML Collection' must have a '[Symbol.iterator]()' method that returns an iterator
。
我的 map :
map(
([headRow, bodyRows]: [HTMLTableRowElement, HTMLCollectionOf<HTMLTableRowElement>]) => [
[...headRow.children].map(headerCell => headerCell.textContent), // First issue
[...bodyRows].map(row => [...row.children]) // Second issue
]
),
如何最好地处理这个问题?对我有什么建议吗?
最佳答案
HTMLCollection 不可迭代,但您可以通过在 HTML 元素上使用“any”来让它忽略它。
([headRow, bodyRows]: [
HTMLTableRowElement,
HTMLCollectionOf<HTMLTableRowElement>
]) => [
[...(<any>headRow.children)].map(
(headerCell) => headerCell.textContent
),
[...(<any>bodyRows)].map((row) => [...row.children])```
关于angular - 类型 'HTML Collection' 必须有一个 '[Symbol.iterator]()' 方法返回指令中的迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61075183/