【发布时间】:2018-09-17 12:25:43
【问题描述】:
我在表格中使用 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)
}
},
''
); });
突然间,它开始给我一个错误,“'NodeList' 类型上不存在属性 'forEach'。”。在它工作正常之前我没有做任何更改。
【问题讨论】:
-
在操场上运行良好 typescriptlang.org/play/… 你的 tsconfig.json 是什么样的?
-
{ "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "声明”:false,“moduleResolution”:“node”,“emitDecoratorMetadata”:true,“experimentalDecorators”:true,“target”:“es5”,“typeRoots”:[“node_modules/@types”],“lib”: [“es2017”,“dom”]}}
-
@TitianCernicova-Dragomir 看起来像那样
-
看起来不错,一个潜在的错误来源可能是你在
lib选项中遗漏了dom,但事实并非如此。它应该工作...... -
如果你跳转到
childNodes的声明,你看到了什么?应该是readonly childNodes: NodeListOf<Node & ChildNode>。
标签: angular typescript angular6 dragula angular-dragula