2

我在指令中有一张显示错误代码的地图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
  ]
),

我如何最好地处理这个问题?有什么建议给我吗?

4

1 回答 1

0

HTMLCollection 不可迭代,但您可以通过在 HTML 元素上使用“any”来忽略它。

          ([headRow, bodyRows]: [
            HTMLTableRowElement,
            HTMLCollectionOf<HTMLTableRowElement>
          ]) => [
            [...(<any>headRow.children)].map(
              (headerCell) => headerCell.textContent
            ),
            [...(<any>bodyRows)].map((row) => [...row.children])```
于 2020-06-02T16:57:29.973 回答