小编Luw*_*lle的帖子

有没有办法避免在 Ionic 3 中的列表更新后视图闪烁?

我是 Ionic 3 和 firebase 的新手,我正在尝试做一个聊天功能。我的问题是当我用新值更新数组时,视图中的整个列表似乎闪烁/闪烁。有没有办法防止这种情况?我需要更改我的代码吗?

代码(用户聊天.ts)

getChats(){  
//Add by index idea to avoid blinking?
this.chatObserver = this.db.list('chat', ref => ref.child(this.authKey).orderByChild('timestamp'))
  .snapshotChanges().subscribe( snapshot => {
    let reversedSnap = snapshot.slice().reverse();
    let chatArray = [];
    reversedSnap.forEach( element =>{
      let data = element.payload.val();
      data['id'] = element.key;

      this.db.list('profile', ref=> ref.child(data['receiver'])).query.once('value', profileSnap => {
          let profileData = profileSnap.val();
          data['firstName'] = profileData.firstName;
          data['lastName'] = profileData.lastName;
          data['userImage'] = profileData.photos[0];
          data['userKey'] = profileSnap.key;
      })
      this.db.list('messages', ref=> ref.child(this.authKey).child(data['id']).orderByChild('timestamp').limitToLast(1))
        .query.once('value', messageSnap =>{
          messageSnap.forEach( element =>{  //only returns one, foreach to …
Run Code Online (Sandbox Code Playgroud)

firebase ionic2 ionic3 angular

4
推荐指数
2
解决办法
2476
查看次数

标签 统计

angular ×1

firebase ×1

ionic2 ×1

ionic3 ×1