Each in date JSON jquery

1

I'm trying to walk through a array de objetos with jquery I'm doing this:

    $.getJSON('http://localhost:8000/produtos', function(data) {
        $(data).each(function (item) {
            console.log(item);
            $('.product-slider').append(item.NmProduto);
        });

        console.log(data);
    });

At first console.log(item) is exiting 0 1 2 3 . In the command $('.product-slider').append(item.NmProduto); is not doing anything and if I log console in item.NmProduto out undefined , already in my console.log(data) the right information is coming like no in the following print:

I need to set an html in this div my with data coming from json , what is the best way to develop this?

    
asked by anonymous 04.10.2016 / 02:32

1 answer

1

You're getting chave of array and you actually need value , so use < $. each like this:

$.getJSON('http://localhost:8000/produtos', function(data) {
    $.each(data, function (key, item) {
        //console.log(item);
        $('.product-slider').append(item.NmProduto);
    });
});

Examples of using array with jQuery .

    
04.10.2016 / 02:45