xxxxxxxxxx
1
<div id="async" class="form-outline autocomplete" data-mdb-input-init>
2
<input type="text" id="form2" class="form-control" />
3
<label class="form-label" for="form2">Example label</label>
4
</div>
1
1
xxxxxxxxxx
1
const asyncAutocomplete = document.querySelector('#async');
2
const asyncFilter = async (query) => {
3
const url = `https://swapi.py4e.com/api/people/?search=${encodeURI(query)}`;
4
const response = await fetch(url);
5
const data = await response.json();
6
return data.results;
7
};
8
9
new mdb.Autocomplete(asyncAutocomplete, {
10
filter: asyncFilter,
11
displayValue: (value) => value.name&value.height
12
});
Console errors: 0