【发布时间】:2017-11-20 23:23:52
【问题描述】:
我订阅了 FirebaseObjectObservable,以便从我的 firebase 数据库中获取对象的属性值。该属性可以包含多个值,因此我将这些值存储在本地数组变量中。
但我无法使用 forEach 遍历这个局部数组变量。所以我 console.log 这个数组变量。这个变量似乎有 json 格式,也许这就是我无法迭代的原因。请帮我找到一种方法来遍历这个变量。
* 代码和控制台图像:
* 编辑 *
我将 subscribe 方法中的代码转移到迭代。
getAttachments() {
this.assignment.subscribe(asnDetails => {
if (asnDetails.fileKey) {
this.fileKeys.push(asnDetails.fileKey);
this.fileKeys[0].forEach(asnFileKey => { // <---- shifted this forEach loop inside subscribe
this.asnFiles = this._getAsnService.getAssignmentFiles(asnFileKey);
this.asnFiles.subscribe(file => {
this.fileNames.push(file.name);
});
});
}
});
}
【问题讨论】:
-
请在问题中输入相关代码。另外,请用正确的国际英语书写,其中“I”一词大写。最后,请不要详细说明您在学习曲线中的位置,或者您对未来答案的感激之情。
标签: angular typescript firebase firebase-realtime-database rxjs