async getListOfFiles(){
if(this.service.wd == '') {
await getBasic((this.service.wd));
} else {
await getBasic(('/'+this.service.wd));
}
this.files = await JSON.parse(localStorage.getItem('FILENAMES'));
var filesList = document.getElementById(this.trackLine.toString());
var li;
for (var i = 0; i < this.files.length; i++) {
li = document.createElement('li');
li.appendChild(document.createTextNode(this.files[i].name));
filesList.appendChild(li);
}
localStorage.clear();
}
I am facing an issue where I need to wait for the 'getBasic' function and JSON parsing to finish before displaying the values on the DOM. Currently, I am getting values from the previous call every time, which indicates that the asynchronous process is not working as expected. As I do not have much TypeScript experience, it's challenging for me to debug this.
Edit: The 'getBasic' function is a JavaScript function integrated into this application quite delicately, and I was hoping to avoid dealing with it directly.
var getBasic = function (path) {
var ACCESS_TOKEN = '';
var dbx = new Dropbox({ accessToken: ACCESS_TOKEN });
dbx.filesListFolder({ path: path })
.then(function (response) {
localStorage.setItem('FILENAMES',JSON.stringify(response.entries));
console.log(response);
})
.catch(function (error) {
console.error(error);
});
return false;
}