Reputation: 21864
typeahead.js has the prefetch
options to get the datums before they are needed.
$('input').typeahead({
"prefetch": "/selections_url"
});
What I would like is to filter the selection based on some information in the document. prefetch
can also filter the initial datums when using the filter
option. But this only filters the initial fetch. What I need is indeed prefetch
but with a hook to filter out some datum just before they are displayed.
typeahead.js has this event typeahead:opened
but this has no arguments (cannot process datums) and is triggered before the datums are rendered in the dropdown (so I cannot write a piece of code to remove some rendered datums)
Any way to do this?
PS: I have also added this issue in the typeahead.js project.
Upvotes: 3
Views: 337
Reputation: 13598
I suppose you could use remote
(making an AJAX call) and pass your document data to the server side, and have the server side populate.
A hack is immediately implied:
Use prefetch
, and in its filter
store a reference to the data. Have the filter()
itself return an empty set.
Have an empty remote URL (or a URL that points to an endpoint that does nothing), and in its filter
, read the data that you stored in prefetch
's filter
, do whatever you want with your document data, and return any subset of that.
Upvotes: 2