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



我正在使用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)
}         
},
''
);   });

突然之间,它开始给我错误,即"属性'forEach'在类型'NodeList'上不存在。在它工作正常之前,我没有做任何更改。

我在tsconfig.json的lib中添加了属性"dom.iterable",它可以工作

另一种方式:

  • 使用点差运算符:

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

最新更新