javascript - Bootstrap Typeahead : How to get all fetched remote values in typeahead bind function -
is possible fetched remote values in typeahead bind function.
var banknames = new bloodhound({ datumtokenizer: function (datum) { return bloodhound.tokenizers.whitespace(datum.value); }, querytokenizer: bloodhound.tokenizers.whitespace, limit: 10, remote: { url: '/payments/bankwithdrawal/bankdetails?str=%query, prepare: function (query, settings) { var encoded = query.tounicode(); settings.url = settings.url.replace('%query', encoded); return settings; } } }); banknames.initialize(); // initializing typeahead $('.typeahead').typeahead({ hint: true, highlight: true, // enable substring highlighting minlength: 1 // specify minimum characters required showing result }, { name: 'bankname', source: banknames }).bind('change blur', function () { console.log(banknames); console.log(banknames.index.datums); });
it should give me banknames in banknames.index.datums
giving me
object {} __proto__: object constructor: function object() hasownproperty: function hasownproperty() isprototypeof: function isprototypeof() propertyisenumerable: function propertyisenumerable() tolocalestring: function tolocalestring() tostring: function tostring() valueof: function valueof() __definegetter__: function __definegetter__() __definesetter__: function __definesetter__() __lookupgetter__: function __lookupgetter__() __lookupsetter__: function __lookupsetter__() __proto__: function __proto__() set __proto__: function __proto__()
i need banknames in bind function need perform action.
when printing in bind function console.log(banknames)
should return me fetched remote values.
any highly appreciated.
i got solution of transform
part of bloodhound
. when configuring remote option, transform
options available.
transform – function signature transform(response) allows transform remote response before bloodhound instance operates on it.
you can read more bloodhound option in link https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md#remote
var banknamelist; var banknames = new bloodhound({ datumtokenizer: function (datum) { return bloodhound.tokenizers.whitespace(datum.value); }, querytokenizer: bloodhound.tokenizers.whitespace, limit: 10, remote: { url: '/payments/bankwithdrawal/bankdetails?str=%query, prepare: function (query, settings) { var encoded = query.tounicode(); settings.url = settings.url.replace('%query', encoded); return settings; }, transform : function (data) { banknamelist = data; return data; } } }); banknames.initialize(); // initializing typeahead $('.typeahead').typeahead({ hint: true, highlight: true, // enable substring highlighting minlength: 1 // specify minimum characters required showing result }, { name: 'bankname', source: banknames }).bind('change blur', function () { console.log(banknamelist); });
now if print banknamelist inside bind
function of typeahead console.log(banknamelist);
print data fetched remote.
Comments
Post a Comment