I have problems with printing to html an array with json objects. The original code Im using is this for the javascrit object that is the "shopping cart"
var ShoppingCart = {
Id: 1,
ShoppingCartItems: [] //array with json objects
};
And the array in the "ShoppinCartItems"
{Id:1,ShoppingCartItems:[{ProductID:"9",Quantity:"2",Price:"68.40",Name:"Cake",Date:"2014-05-30",StoreID:"1",UserID:"1"},{ProductID:"7",Quantity:"1",Price:"11.40",Name:"Donut",Date:"2014-05-30",StoreID:"1",UserID:"1"}]}
(I dont know if this is valid because im using an example.)
So with this array of json objects I want to display a table in html displayin those values group by date. The actual code Im using is this:
$.each(ShoppingCart.ShoppingCartItems, function (i, Productos) {
$(".cart").append("\
<tr style='background-color: #F1F1F1; border-bottom: 3px solid #fff;'>\
<td style='width: 10%;'>" + Number(Productos.Quantity) + "</td>\
<td style='width: 33%'>" + Productos.Name + "</td>\
<td style='width: 33%'>" + (Productos.Date || 'N/A') + "</td>\
<td style='width: 20%'>" + Productos.Price + "</td>\
</tr>");
}); //each
But unfortunately the result will be like this
Qty Name Price
2014-05-30
2 Cake 68
2014-05-30
1 Donut 10 (e.g.)
And the result I want is this
Qty Name Price
May 30, 2014
2 Cake 68
1 Donut 10 (e.g.)
---
May 31, 2014
1 Other product 10.00
I want the products grouped by date but I cant manage to group by from the json array of every product, I dont know which is the bes solution, hope someone can help me
Thanks