Show more than one result json

1
function OrdersCallback(json) {
for (var o = 0; o < json.length; o++) {
$('#summary').append('<b>Order Number:</b> ' + json[o].order_number + '<br />');
$('#summary').append('<b>Item:</b> ' + json[o].line_items[0].name + '<br />');
$('#summary').append('<b>Customer:</b> ' + json[o].customer.billing_address.first_name + '<br />');
$('#summary').append('<b>Status:</b> ' + json[o].status + '<br />');
$('#summary').append('<b>Total:</b> ' + json[o].total + '<br />');
$('#summary').append('<hr />');
}
}

in the next

$('#summary').append('<b>Item:</b> ' + json[o].line_items[0].name + '<br />');

There is more than one result, but I do not know how to show all, it shows only 1.

here my code

link

    
asked by Juan David 28.03.2017 в 20:58
source

1 answer

4

Applying the map () method to iterate the objects returned by json[o].line_items and JOIN to separate the returned items (",")

 $('#summary').append('<b>Item:</b> ' + 
               json[o].line_items.map(function(elem){
                      return elem.name;
               }).join(",") + '<br />');
    
answered by 28.03.2017 / 21:14
source