Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support local being a function #485

Closed
ansman opened this issue Oct 15, 2013 · 10 comments
Closed

Support local being a function #485

ansman opened this issue Oct 15, 2013 · 10 comments

Comments

@ansman
Copy link

ansman commented Oct 15, 2013

Coming from Bootstrap's typeahead I'm used to being able specify the source being a function that returns an array of items.

I would love to see this functionality in typeahead.js too.

The specification is quite simple, allow the local argument of a dataset to be a function that when called returns the same array that is today expected.

@pavelnikolov
Copy link

I would like the same feature. I have an Angular app. My data comes from a $q promise and I already make the $http request to the server because I need the data for other page elements too. I want to assign the datasources after I get the data later in the page lifecycle. Any help would be much appreciated. I think being able use function instead of a static array would help me too.

@akshayrawat
Copy link

+1

@adambiggs
Copy link

+1

Similar scenario. We're using Spine.js, so the data already exists as records in client-side models. I want Typeahead.js to fetch fresh data from the model each time it's opened.

Currently, it seems the only option is to convert the model data into datums when Typeahead.js is instantiated... But then data becomes stale as soon as model records change...

The old bootstrap typeahead could handle this with the source option.

@adambiggs
Copy link

Looks like #370 might fix this.

@adambiggs
Copy link

Hopefully this feature can make it into v0.10 (#335)

@ansman
Copy link
Author

ansman commented Dec 2, 2013

#370 only calls the function once right (in the constructor), I'd like to have it be called every time a search is performed.

@adambiggs
Copy link

Oh ya didn't notice that, totally agree @ansman.

@bkCDL
Copy link

bkCDL commented Dec 9, 2013

+1
I have a similar situation too, as I'm using Ember and want to point the typeahead to a model's RESTAdapter that handles all the filtering/requerying/etc itself. When I use 'local, I do find that typeahead doesn't wait for the adapter's promise to be resolved and returns a "datum is undefined" error. See this discussion: http://stackoverflow.com/questions/20410558/using-an-ember-data-model-in-typeahead/20412682

@jharding
Copy link
Contributor

I'll look into this for v0.10.1.

@jharding
Copy link
Contributor

jharding commented Feb 4, 2014

#370 only calls the function once right (in the constructor), I'd like to have it be called every time a search is performed.

@ansman, you can now achieve this by defining your own source starting in v0.10.0.

FYI, I'm still going to make the change that allows local to be a function that returns an array of datums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants