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

Allow remote to be a callback #8

Closed
koen-serry opened this issue Feb 20, 2013 · 6 comments
Closed

Allow remote to be a callback #8

koen-serry opened this issue Feb 20, 2013 · 6 comments
Milestone

Comments

@koen-serry
Copy link

If the remote returns something where the dataset is nested, you can't extract the dataset from it. It would also allow to customise the call to the backend if some extra headers were to be set.

@jharding
Copy link
Contributor

I like this idea, what if we supported something like the this:

$('.typeahead').typeahead({
  name: 'remoteTest',
  remote: {
    url: 'http://example.com?q=%QUERY',
    beforeSend: function(jqXhr, settings) {
       // set headers      
    },
    success: function(resp, status, jqXhr) {
      // return nested data from response
    }
  }
});

Would that offer the flexibility you're looking for?

@adamtoth
Copy link

+1 for this.

I'd love to use this in SharePoint, but the JSON data I get back from its REST services are heavily nested, and I'd need to translate it to a dto to work with the data set expected format.

@koen-serry
Copy link
Author

I'm still wondering why the separation between local and remote. Can't we just create a datasource property, if it's a function it uses the contents of the return (possibly ajax) in all other cases it just uses the object.

@eads
Copy link

eads commented Sep 25, 2013

I hate to be annoying and revisit an old issue, but I am running into a similar issue and this doesn't quite address it. For my use case, I could really use a remote or another way of specifying a datasource that as @koen-serry says "if it's a function it uses the contents of the return (possibly ajax)".

I'm using typeahead JS in a scenario where I have a remote data source that I must use to get some event listing data. However, the API's search feature is so screwed up that we're using LunrJS to handle all search client side.

What I'd love to see is something along these lines:

var searchIndex = lunr( ... );

$('.typeahead').typeahead({
  name: 'localSearchTest',
  remote: function(input) {
    return searchIndex.search(input);
  }
})

In real life, you'd need to do a little more processing with the search results to get a list that was useful for typeaheadJS, but the fundamental thing is some way to support a function that returns a list in addition to a static list and a remote endpoint.

(P.S. Thanks for the fantastic library. This thing is amazing!)

@rgravina
Copy link

I'm also wondering how to work around this issue in order to use Bloodhound prefetching etc.

In my case, remote data comes from an API call with a success callback function.

Without Bloodhound, you can use a callback using the source parameter and everything is fine. With Bloodhound however, local expects an array of values to be returned, and remote expects a URL.

Am I missing something obvious?

@aribornstein
Copy link

Was this resolved if so how do I access the nested data?

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

Successfully merging a pull request may close this issue.

6 participants