Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So first, typeahead.js doesn't do any sort of filtering on the data returned by <code>remote</code>. It's expected that the data returned by <code>remote</code> already contains valid suggestions for the given query.</p> <p>It sounds like using <code>prefetch</code> may be a better option if you're expecting typeahead.js to handle matching suggestions to a query and since you have ~700 entries, you should see pretty solid performance. If you choose to go down that path, you'd want to do something like this:</p> <pre class="lang-js prettyprint-override"><code>$('input[name="s"]').typeahead({ name: 'search', prefetch: { url: '/path/to/json/file/that/returns/all/entries', filter: removeLastNameFromTokens }, template: '&lt;p&gt;&lt;a href="{{url}}"&gt;{{value}}&lt;/a&gt;&lt;/p&gt;', engine: Hogan }); function removeLastNameFromTokens(data) { var datum, firstName; for (var i = 0; i &lt; data.length; i++) { datum = data[i]; datum.tokens.pop(); // assumes tokens looks like [First, Last] } return data; } </code></pre> <p>Assuming <code>/path/to/json/file/that/returns/all/entries</code> points to a JSON file that contains an array of datums, <code>removeLastNameFromTokens</code> will iterate through each datum and remove the last name from <code>tokens</code>, leaving only the first name. This should result in the functionality you're looking for.</p> <p>Another good strategy would be to use a combination of <code>prefetch</code> and <code>remote</code>. You could include the 100 or so most popular entries in the <code>prefetch</code> data and then rely on <code>remote</code> to backfill suggestions when <code>prefetch</code> can't produce enough suggestions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload