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

Bloodhound optionally indexes/matches remote data (backport to master) #1154

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/bloodhound.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ When configuring `remote`, the following options are available.
transforms the response body into an array of datums. Expected to return an
array of datums.

* `indexResponse` - If `true`, causes data fetched from remote to be added to
the index, along with local and prefetched data. This is useful, for example,
when trying to confirm that new tokens were suggested before adding them.
Defaults to `false`.

* `ajax` – The [ajax settings object] passed to `jQuery.ajax`.

<!-- section links -->
Expand Down
5 changes: 4 additions & 1 deletion src/bloodhound/bloodhound.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@
return this.transport.get(url, this.remote.ajax, handleRemoteResponse);

function handleRemoteResponse(err, resp) {
err ? cb([]) : cb(that.remote.filter ? that.remote.filter(resp) : resp);
var data=that.remote.filter ? that.remote.filter(resp) : resp;
if(that.remote.indexResponse)
that.add(data);
err ? cb([]) : cb(data);
}
},

Expand Down
1 change: 1 addition & 0 deletions src/bloodhound/options_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var oParser = (function() {
rateLimitWait: 300,
send: null,
filter: null,
indexResponse: false,
ajax: {}
};

Expand Down