Why does bloodhound.get() return undefined?

前端 未结 1 1611
轻奢々
轻奢々 2021-01-20 11:07

I\'m trying to use the code below with typeahead.js v 0.10

// instantiate the bloodhound suggestion engine
var numbers = new Bloodhound({
datumTokenizer: fun         


        
相关标签:
1条回答
  • 2021-01-20 11:14

    I implemented Bloodhound.get() as follows (also see this fiddle : http://jsfiddle.net/Fresh/HS9Wy/):

    // instantiate the bloodhound suggestion engine
    var numbers = new Bloodhound({
        datumTokenizer: function (d) {
            return d;
        },
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        local: ["(A)labama", "Alaska", "Arizona", "Arkansas"]
    });
    
    // initialize the bloodhound suggestion engine
    numbers.initialize();
    
    // Get an array of datums which satisfy the query for 'a'
    numbers.get('a', function (suggestions) {
        jQuery.each(suggestions, function (index, item) {
            console.log(item);
        });
    });
    

    The problem with your call to "get()" i.e.

    numbers.get('a')
    

    Is that whilst you are getting Bloodhound to execute the query for 'a' you are not doing anything with the results. To instruct "get()" to do something useful you need to send the results to the output function. See the documentation here.

    0 讨论(0)
提交回复
热议问题