0
我不確定我的問題是否可能,但我問是否有任何方法可以使實時更新的數組列表是否可以在Ionic2中實時更新臨時陣列?
例如,我使用「setInterval」來更新我的臨時數組列表:
public usersList: FirebaseListObservable <any[]> ;
public chatsList: FirebaseListObservable <any[]> ;
public tempList = [];
public refreshIntervalId;
constructor(...) {
this.usersList = this.afd.list('/users/');
this.chatsList = this.afd.list('/chats/');
this.refreshIntervalId = setInterval(() => {
this.joinObjects();
}, 250);
}
joinObjects() {
let TempListX = [];
this.chatsList.take(1).subscribe(data1 => {
this.usersList.take(1).subscribe(data2 => {
TempListX = data1.slice(0);
for (let i = 0; i < data1.length; i++) {
for (let j = 0; j < data2.length; j++) {
if (data1[i].user_id == data2[j].$key) {
TempListX[i].fname = data2[j].fname;
TempListX[i].lname = data2[j].lname;
TempListX[i].uemail = data2[j].email;
TempListX[i].uid = data2[j].$key;
}
}
}
if (JSON.stringify(TempListX) === JSON.stringify(this.tempList)) {}
else {
this.tempList = TempListX.slice();
}
})
})
}
那麼有沒有比「setInterval」更好的方法?