Personally, I have a servlet that returns a Map via Json and I would like to use the values of this map (key and value) to populate a table via Ajax.
My code in Ajax are as follows below:
success:function(responseJson){
$(".results").show();
$(".content").show();
var headTable = $(".tablesorter > thead > tr");
var bodyTable = $(".tablesorter > tbody > tr");
$.each(responseJson, function(key, value){
$("<th>").html(key).appendTo(headTable);
for (var i = 0; i < value.length; i++){
$("<td>").val(key).html(value[i]).appendTo(bodyTable);
}
});
The key of my Map I would like it to be the value of the head of the table and the Map's values were the body of the table.
The table I want to populate the following below:
<table cellspacing="1" class="tablesorter">
<thead>
<tr>
</tr>
</thead>
<tbody>
<tr class="even">
</tr>
</tbody>
However, the way my code to be rather than to create rows with the values from the Map, it be creating multiple columns.
What should I do to my code behave correctly?
Map<"A", "a1,a2,a3">
Map<"B", "b1,b2,b3">
What I wish I was using the values of the Key as the head of the table and with each Key values to create the body of the table. However, the way that my code is not to be working. – Jeovane Reges Feb 02 '13 at 17:08