I'm using typeahead.js 0.9.3 and it's working swimmingly. My question is whether it's possible to remove a datum from a dataset upon the "typeahead:selected" event (or any event, for that matter).
I'm fetching the data in the dataset using Typeahead's prefetch
option on page load. I know that I could call $('selector').typeahead('destroy')
and re-initalize typehead and use a filter
in the prefetch
object, but it seems rather heavyweight to have to call the data all over again (we're not caching the data in local storage).
I suppose I'm looking for something akin to the filter
function to iterate through the array of datums and remove the previously-selected (or all selected) datum. It doesn't look like there's a public function in typeahead to do this, but maybe I missed it.
I've read through typeahead's docs and searched here but haven't found an answer.
EDIT: I solved the immediate problem by switching from prefetch
to local
and using an AJAX post
call to get the data, set it as a global variable and then passed it to typeahead
, where I can add/remove items from the global array of data and then destroy/reinitalize typeahead as needed. Far from ideal, but it works.
.typeahead('destroy')
and re-initializingtypeahead
with anotherprefetch
call. I don't want to have toPOST
after evertypeahead:selected
event. – Beckibeckie