twitter / typeahead.js

typeahead.js is a fast and fully-featured autocomplete library
http://twitter.github.io/typeahead.js/
MIT License
16.52k stars 3.21k forks source link

remote bloodhound not working #1584

Open basith374 opened 7 years ago

basith374 commented 7 years ago

can i get a proper example for a typeahead using bloodhound remote? none of the solutions from other solutions works for me. i am working on this type of dataset

{
    "status": "success",
    "products": [
         {
            "id": "1",
            "name": "Milky Mist",
         },
         {
            "id":"2",
            "name": "Medimix",
         }
    ]
}

and the configuration is

var engine = new Bloodhound({
    remote: {
        url: '/products?q=%QUERY',
    wildcard: '%QUERY',
    transform: function(data) {
        return data.products;
    }
    },
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    datumTokenizer: Bloodhound.tokenizers.whitespace('name')
});
$('.typeahead').typeahead({
    source: engine.ttAdapter()
});

the xhr requests are fired but nothing is displayed. i've tried this solution but this error throws up:

bloodhound.min.js:7 Uncaught TypeError: c is not a function
jlbooker commented 7 years ago

@basith374 Try using the non-minified version. This should give you a more accurate error message with a better line number.

John-Blair commented 5 years ago

I had same problem - looking at the typeahead bundle the dataTokenizer was an array not a function when whitespace above was passed a property name. I changed that line to datumTokenizer: Bloodhound.tokenizers.whitespace - ie remove the object property name being passed in, and the error went away. This seems a really buggy plugin - all the examples change from 1 version to the next and you never know what version a web search is for....truly awful situation.