我不确定我的问题是否可行,但我想问是否有办法让一个实时更新的arraylist
例如,我使用&#34; setInterval&#34;更新我的临时arraylist,如: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();
}
})
})
}
那么有什么方法比#34; setInterval&#34;更好。 ?