Json does not load in TypeHead lib

0

Beauty? I have a Json whose structure is as follows:

[{"id":1,"nome":"teste"},{"id":2,"nome":"teste"},{"id":3,"nome":"teste3"}]

I want to use it in this type head code but however it does not load ... In the browser console it shows that it loaded json correctly.

In Ajax's return, I already return with json type ...

$('#nome').typeahead({
    source: function(query, process) {
        objects = [];
        map = {};
        console.log(data);
        $.each(data, function(i, object) {
            map[object.label] = object;
            objects.push(object.label);
        });
        process(objects);
    },
    updater: function(item) {
        console.log(map[item].id);
        //$('hiddenInputElement').val(map[item].id);
        return item;
    }
});

return error in console:

  

TypeError: b is undefined

    
asked by anonymous 28.07.2016 / 03:42

1 answer

0

Solved, I changed the json key from "name" to "label" and there it worked.

    
28.07.2016 / 13:37