'Twitter Typeahead Searching Comma Separated Values

I'm using typeahead v0.11.1, it all appears to be working apart form one thing.

I am searching a JSON dataset, a snippet of this can be seen below;

[
  {
    "last_name": "Jo",
    "first_name": "Smith",
    "location": "Plum,Newton"
  },
  {
    "last_name": "Sara",
    "first_name": "Gates",
    "location": "Bread"
  }
]

The issue I'm having is with the location values. If the location contains a comma seperated list of values, only the first one is searchable / discoverable.

These are the results of some searches;

  • Searching for plu > finds Plum,Newton
  • Searching for new > no results found

Do I need some sor of custom function the splits the comma seperated values? I've never seen this done before but I know it's possible to override the source option using a function - not sure if this is what I need or not?

Any help is appreciated.



Solution 1:[1]

https://dotnetfiddle.net/5zmyzT

I went ahead and wrote a fiddle that parses the location, and allows typeahead to work against comma separated values.

Overriding the source options will not work, as we need to split our values.

https://dotnetfiddle.net/5zmyzT

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1