autocomplete: store query string on Suggestion instance
This commit is contained in:
parent
bbf4c08ffd
commit
a72ad8a53d
@ -86,9 +86,17 @@ const helpers = {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An autocomplete suggestion
|
||||
*/
|
||||
class Suggestion extends String {
|
||||
|
||||
constructor (data) {
|
||||
/**
|
||||
* @param { Any } data - The auto-complete data. Ideally an object e.g. { label, value },
|
||||
* which specifies the value and human-presentable label of the suggestion.
|
||||
* @param { string } query - The query string being auto-completed
|
||||
*/
|
||||
constructor (data, query) {
|
||||
super();
|
||||
const o = Array.isArray(data)
|
||||
? { label: data[0], value: data[1] }
|
||||
@ -96,6 +104,7 @@ class Suggestion extends String {
|
||||
|
||||
this.label = o.label || o.value;
|
||||
this.value = o.value;
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
get lenth () {
|
||||
@ -381,7 +390,7 @@ export class AutoComplete {
|
||||
this.ul.innerHTML = "";
|
||||
|
||||
this.suggestions = list
|
||||
.map(item => new Suggestion(this.data(item, value)))
|
||||
.map(item => new Suggestion(this.data(item, value), value))
|
||||
.filter(item => this.filter(item, value));
|
||||
|
||||
if (this.sort !== false) {
|
||||
|
Loading…
Reference in New Issue
Block a user