Why does bloodhound.get() return undefined?

爷,独闯天下 提交于 2019-12-01 22:35:32

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!