Question

I'm trying to make Bloodhound work.

The code I have:

var licenses = new Bloodhound({
        datumTokenizer: function(d) {
            return Bloodhound.tokenizers.whitespace(d.value);
        },
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        local: [{ "value": 1 , "text": "A"}, { "value": 2 , "text": "C+E"}]
    });

licenses.initialize();

throws an error

Object 1 has no method 'split'

What's wrong in this code?

Was it helpful?

Solution

If you want to use a number as search term you must convert it as string like:

$(document).ready(function () {
    var numbers;

    numbers = new Bloodhound({
        datumTokenizer: function (d) {
            return Bloodhound.tokenizers.whitespace(d.value.toString());
        },
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        local: [{ "value": 1 , "text": "A"}, { "value": 2 , "text": "C+E"}]
    });

    numbers.initialize();

    $('.typeahead').typeahead(null, {
        displayKey: 'value',
        source: numbers.ttAdapter()
    });

});

Demo: http://jsfiddle.net/IrvinDominin/6HSMA/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top