我有这个递归函数,它调用一个服务来生成和HTTP请求并返回true或false。如果是的话,我将一个字符串推入this.data
数组。然后,视图使用this.data
来显示列表。
问题是,视图没有自动更新。有没有办法以编程方式刷新视图?还是比这简单?
非常感谢
JT
checkForFile(dateToday: Date, fileListArray: Array<string>, numberOfFilesToCheck: number) {
// create the filename to search for
let dateYesterday: Date = this.createDateForYesterday(dateToday);
let filenameYesterday = this.createFilenameForDate(dateYesterday) + '_activities.csv';
this.serverDataService.fileExists(filenameYesterday)
.toPromise()
.then((data) => { // the callback where it all happens
if (data === true) {
this.data.push(filenameYesterday);
}
// recurse this method until the array is full.
if (this.data.length < numberOfFilesToCheck) {
this.checkForFile(dateYesterday, fileListArray, numberOfFilesToCheck, callCount);
} else {
return;
}
});
}