Pārlūkot izejas kodu

autocomplete: store query string on Suggestion instance

JC Brand 4 gadi atpakaļ
vecāks
revīzija
a72ad8a53d
1 mainītis faili ar 11 papildinājumiem un 2 dzēšanām
  1. 11 2
      src/converse-autocomplete.js

+ 11 - 2
src/converse-autocomplete.js

@@ -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) {