ok, you cannot use async
methods in array filter
as it is synchronous. Instead you could loop through each item one by one and use await
keyword. Make changes as mentioned below:
- First, return a promise from your
phraseFound
method like below:
phraseFound(path: string, phrase: string) {
let panelMediaFile = 'panelMedia_' + this.global.langAbbv + '.json'; // e.g. "panelMedia_en.json"
//
return new Promise((resolve) => {
this.file.readAsText(this.global.fileSystem.int + path, panelMediaFile).then((jsonStr) => {
resolve(jsonStr.toLowerCase().indexOf(phrase) === -1);
}).catch((err) => {
this.global.showError('t10', err);
});
});
}
- Second, loop through your
filteredItems
items one by one and use theawait
keyword to wait for the promise to return the value.
var filtered_results = [];
for(var i=0;i<filteredItems.length;++i){
let tapaSrcPath = this.global.path.titles + filteredItems[i].titleURI + '/tapaSrc/';
let found = await this.phraseFound(tapaSrcPath, searchTermsPhrase).then((found) => {
return found;
});
if(found){
filtered_results.push(filteredItems[i]);
}
}
filteredItems = filtered_results;
- Third, since you are using
await
in the second step, you will need to changesearchSortTapaskills
toasync searchSortTapaskills
.
This should do the trick for you.