I am trying to write an Obsidian plugin. I am stuck with Promise object when trying to call an API for example and trying to fill the results object inside query
function.
How can I possibly fill results object inside query
function.
Note that I cannot change the signature of getItems
method as it is from the Obsidian base class FuzzySuggestModal
.
export default class DictionarySuggester extends FuzzySuggestModal<string> {
async getAutocompleteItems(term: string) {
const response = await request({ url: this.autocompleteUrl.replace('{0}', term) });
return response;
}
query(term: string): any {
const results = [];
const searchTerm = term.toLocaleLowerCase();
// Problem here, calling await
var response = await this.getAutocompleteItems(searchTerm);
var jsonObj = JSON.parse(response);
for(var i = 0; i < jsonObj.results.length; i++) {
var term= jsonObj.results[i].term;
results.push(term);
}
return results;
}
getItems(): string[] {
let searchTerm = '';
// logic to get the searchTerm
return searchTerm === '' ? [] : this.query(searchTerm);
}
}