我在指令中的地图上显示了错误代码。TS2488 Type 'HTML Collection' must have a '[Symbol.iterator]()' method that returns an iterator
.
我的地图
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])```