'HTML Collection'类型必须有一个'[Symbol.iterator]()'方法,在指令中返回一个迭代器。

问题描述 投票:1回答:1

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

我怎样才能最好地处理这个问题?有什么建议给我吗?

angular iterator directive htmlcollection
1个回答
0
投票

HTMLCollection是不可迭代的,但你可以通过在你的HTML元素上使用 "any "来让它忽略这一点。

          ([headRow, bodyRows]: [
            HTMLTableRowElement,
            HTMLCollectionOf<HTMLTableRowElement>
          ]) => [
            [...(<any>headRow.children)].map(
              (headerCell) => headerCell.textContent
            ),
            [...(<any>bodyRows)].map((row) => [...row.children])```
© www.soinside.com 2019 - 2024. All rights reserved.