dimanche 17 juillet 2016

Typeahead and Bloodhound - how to get JSON result

I have the json list of Countries: http://vocab.nic.in/rest.php/country/json

And I'm trying to get country_id and country name with Bloodhound suggestion engine. O tried following code:

var countries = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('country_name'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    limit: 10,
    prefetch: {
        url: 'http://vocab.nic.in/rest.php/country/json',
        filter: function(response) {
            return response.countries;
        }
    }
});

$('#my-input').typeahead({
        hint: true,
        highlight: true,
        minLength: 1
    },
    {
        name: 'states',
        displayKey: 'value',
        source: countries.ttAdapter()
    });

Which doesn't work. How should I change the code to make this work?

Aucun commentaire:

Enregistrer un commentaire