Firebase 为什么for循环在ionic ionViewWillEnter方法中不起作用

Firebase 为什么for循环在ionic ionViewWillEnter方法中不起作用,firebase,ionic-framework,Firebase,Ionic Framework,我在ionViewWillEnter()方法中调用了一个方法“allComments()”,但每次我在视图中输入时,它都不会绑定名称和概要文件。找不到任何有效的理由。代码中没有错误 allComments() { this.comments=[]; let arr=[]; this.com=[]; console.log(this.challengeId) this.https.get('https://dareost.firebaseio.com/comments/' +this.challe

我在ionViewWillEnter()方法中调用了一个方法“allComments()”,但每次我在视图中输入时,它都不会绑定名称和概要文件。找不到任何有效的理由。代码中没有错误

allComments() {
this.comments=[];
let arr=[];
this.com=[];
console.log(this.challengeId)
this.https.get('https://dareost.firebaseio.com/comments/'
+this.challengeId+'.json').map(res=>res.json()).subscribe(x=>{
 this.com=x

for(let key in this.com) {
   this.comments.push(this.com[key])
 }
this.length = this.comments.length;

for(let i=0;i<this.comments.length;i++){
 let a=this.comments[i]
 console.log(a)
for(let key in a){

arr.push(a[key])
this.arr.push(a[key])

}


}


 for(let i=0;i<this.arr.length;i++){
   for(let j=0;j<this.users.length;j++){
    console.log(this.arr[i].commentedBy)

    if(this.arr[i].commentedBy == this.users[j].uid){
      console.log(this.users[j].name1)
      this.arr[i].name=this.users[j].name1
       console.log(this.arr[i])
      this.arr[i].profile=this.users[j].profileUrl
      }
    }
    }
allComments(){
这个。注释=[];
设arr=[];
this.com=[];
console.log(this.challengeId)
this.https.get('https://dareost.firebaseio.com/comments/'
+this.challengeId+'.json').map(res=>res.json()).subscribe(x=>{
this.com=x
for(请输入this.com){
this.comments.push(this.com[key])
}
this.length=this.comments.length;

对于(设i=0;iionViewWillEnter()获取的时间较短,重循环和重进程在此期间无法获取进程。这完全取决于设备的RAM。处理速度好的设备不会加载重数据,而处理速度慢的设备可以处理重数据。

循环日志的输出是什么?输出是循环始终在运行n、 循环中记录到console.Btw的那些console.logs是什么?在这种情况下,您应该使用.forEach()为了更好的易读性。你能分享更多的上下文吗?另外,你在一个生命周期钩子中做了大量的重载脚本,这个钩子应该是轻量级的,因为它经常被称为非常轻量级。你能告诉我们如何使它变得轻量级,以及在什么时候它变得很重吗