jquery - Why does bloodhound.get() return undefined? -


i'm trying use code below typeahead.js v 0.10

// instantiate bloodhound suggestion engine var numbers = new bloodhound({ datumtokenizer: function(d) { return d; }, querytokenizer: bloodhound.tokenizers.whitespace, local:  ["(a)labama","alaska","arizona","arkansas"] });  // initialize bloodhound suggestion engine numbers.initialize(); console.log(numbers.get('a')); 

in fact try solve question: https://github.com/bassjobsen/bootstrap-3-typeahead/issues/26 expected shown below should possible:

 $('.typeahead').typeahead( { items: 4, source:function(query){return numbers.get(query)}        }); 

update

the examples. use ttadapter() set source of typeahead. function can used set source property (which accept array of string or function) bootstrap-3-typeahead:

// instantiate bloodhound suggestion engine var numbers = new bloodhound({ datumtokenizer: bloodhound.tokenizers.whitespace,//function(d) { return d; }, querytokenizer: bloodhound.tokenizers.whitespace, local:  ["(a)labama","alaska","arizona","arkansas","arkansas2","barkansas"] });  // initialize bloodhound suggestion engine numbers.initialize();  $('.typeahead').typeahead( { items: 4, source:numbers.ttadapter()   }); 

bloodhound.js shows:

  ttadapter: function ttadapter() {                 return _.bind(this.get, this);             } 

so ttadapter() returns function (get()) can set source has query argument.

i implemented bloodhound.get() follows (also see fiddle : http://jsfiddle.net/fresh/hs9wy/):

// instantiate bloodhound suggestion engine var numbers = new bloodhound({     datumtokenizer: function (d) {         return d;     },     querytokenizer: bloodhound.tokenizers.whitespace,     local: ["(a)labama", "alaska", "arizona", "arkansas"] });  // initialize bloodhound suggestion engine numbers.initialize();  // array of datums satisfy query 'a' numbers.get('a', function (suggestions) {     jquery.each(suggestions, function (index, item) {         console.log(item);     }); }); 

the problem call "get()" i.e.

numbers.get('a') 

is whilst getting bloodhound execute query 'a' not doing results. instruct "get()" useful need send results output function. see documentation here.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -