Json does not click on lib Typehead

Asked

Viewed 25 times

0

beauty? I have a Json whose structure has following:

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

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

On the return of Ajax, 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;
    }
});

returns error in console:

Typeerror: b is Undefined

  • I don’t see b in your code... (?)

1 answer

0


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.