My bloodhound object is reused by two typeaheads, and each typeahead has a hidden image next to it, being these two images: #loading-1
and #loading-2
,
galleriesBloodhound = new Bloodhound({
datumTokenizer: function (gallery) { return gallery.name; },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/GalleriesAjax/List?nameQuery=%QUERY',
beforeSend: function (xhr) {
},
filter: function (response) {
return response.pageOfGalleries;
}
}
});
Typeahead #1:
$("#gallery-name").typeahead({
highlight: false,
hint: true,
},
{
name: 'galleries',
displayKey: function (gallery) { return gallery.displayName; },
source: galleriesBloodhound.ttAdapter()
}).on(..).on(..)...
Typeahead #2 (same code)
$("#gallery2-name").typeahead({
highlight: false,
hint: true,
},
{
name: 'galleries',
displayKey: function (gallery) { return gallery.displayName; },
source: galleriesBloodhound.ttAdapter()
}).on(..).on(..)...
How can I show the correct #loading-1
and #loading-2
while the ajax request has not returned yet?
In typeahead.js's website they suggested using beforeSend
and filter
, but "from there" how can I know which typeahead is the one calling the bloodhound?
beforeSend: function (xhr) {
$("#loading-i").show(); // How do I figure "i" ??
},
filter: function (response) {
$("#loading-i").hide(); // How do I figure "i" ??
return response.pageOfGalleries;
}
// i depends on the typeahead that is using "this" bloodhound