属性 'forEach' 在类型 'NodeList' 上不存在

Property 'forEach' does not exist on type 'NodeList'

我在 Table.

中使用 ng2-dragula 进行拖放
  this.dragulaService.drop.subscribe(value => {     

  let questions_group = value[3] as HTMLTableRowElement        
  let SectionTwo:Array<string> = [];
  let QuestionId:Array<string> = [];
  let OrderNo:Array<number> = [];
  var list2 = questions_group.childNodes;      

  list2.forEach( 
    function(currentValue, currentIndex,listObj) { 

      if(currentIndex!=0){           
        let sectionName2 = currentValue.lastChild.textContent
        SectionTwo.push(sectionName2)
        QuestionId.push(currentValue.firstChild.textContent)
        OrderNo.push(currentIndex)

      }         
    },
    ''
  );   });

突然间它开始给我错误"Property 'forEach' does not exist on type 'NodeList'."。之前它工作正常我没有做任何改变。

我在 tsconfig.json 的 lib 中添加了 属性 "dom.iterable" 并且有效

另一种方式:

  • 使用扩展运算符:

    var list2 = [...questions_group.childNodes]; // Take a look of the syntax
    
    list2.forEach(function(currentValue, currentIndex,listObj) => {
       // Todo
    })