In app.js
in this gist: https://gist.run/?id=acf8253329939b2e046cd0e3394351fe
how does the SuggestionService
work?
export class SuggestionService {
constructor(model, countries) {
this.model = model;
this.countryIndex = countries;
this.countries = Object.keys(countries);
}
country = {
suggest: value => {
if (value === '') {
return Promise.resolve([]);
}
value = value.toLowerCase();
const suggestions = this.countries
.filter(x => x.toLowerCase().indexOf(value) === 0)
.sort();
return Promise.resolve(suggestions);
},
getName: suggestion => suggestion
};
city = {
suggest: value => {
if (value === '' || this.model.country === null) {
return Promise.resolve([]);
}
value = value.toLowerCase();
let suggestions = this.countryIndex[this.model.country]
.filter(x => x.toLowerCase().indexOf(value) === 0);
suggestions = suggestions.filter((x, i) => suggestions.indexOf(x) === i)
.sort();
return Promise.resolve(suggestions);
},
getName: suggestion => suggestion
};
}
I don't understand the line getName: suggestion => suggestion
, I assume it is selecting elements from the suggestions promise, is that correct? How does this work?
In app.html
this suggestion
property is used in a binding:
<span style="font-style: italic">${suggestion}</span>