gpt4 book ai didi

node.js - undefined 不可迭代(无法读取属性 Symbol(Symbol.iterator))

转载 作者:太空宇宙 更新时间:2023-11-04 01:30:34 25 4
gpt4 key购买 nike

我正在尝试循环遍历文件列表以执行删除查询。首先,我从数据库中的表"file"中获取数据,其中属性 "postnumber"=user输入。然后保存到“fileList:Files[]”中。然后循环访问此 fileList 以执行删除查询。但它一直说

"ERROR TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))". See this image =>

error.jpg

forum-admin-list.component.ts

import { FileService } from 'src/app/shared/file.service';
import { Files } from 'src/app/shared/files.model';
export class ForumAdminListComponent {
fileList:Files[];
onDelete(pNo:string){
this.fservice.getPost(pNo).subscribe(actionArray => {
this.fileList = actionArray.map(item => {
return {
id: item.payload.doc.id,
...item.payload.doc.data()
} as Files;
})
});
for(let i of this.fileList){
this.storage.storage.refFromURL(i.path).delete();
this.firestore.doc("files/"+i.id).delete();
}
}
}

files.model.ts

export class Files {
id:string;
pNo:string;
downloadURL:string;
path:string;
}

file.service.ts

export class FileService {
formData: Files;
constructor(private firestore: AngularFirestore) { }

getPost(userRef){
return this.firestore.collection('files',ref=>ref.where('pNo','==',userRef)).snapshotChanges();
}
}

最佳答案

您正在 subscribe() 之外循环遍历 fileList,这意味着它实际上不会等待 Observable 被解析。尝试在 subscribe() 内部循环。

onDelete(pNo:string){ 
this.fservice.getPost(pNo).subscribe(actionArray => {
this.fileList = actionArray.map(item => {
return {
id: item.payload.doc.id,
...item.payload.doc.data()
} as Files[];

for(let i of this.fileList){
this.storage.storage.refFromURL(i.path).delete();
this.firestore.doc("files/"+i.id).delete();
}
})
});
}

此外,您可能希望将订阅结果标记为作为文件[],而不是作为文件

关于node.js - undefined 不可迭代(无法读取属性 Symbol(Symbol.iterator)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56267722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com