senthil rajendran senthil rajendran - 4 months ago 10
jQuery Question

convert string to table content in jsp

String msg= ["{"name":"maha","team":"mahendra"},{"name":"vengi","team":"cisco"},{"name":"anish","team":"goldman"},{"name":"VP","team":"deloitte"},{"name":"senthil","team":"zoho"}"];


from this into table format like,

**name** **team**
maha mahendra
vengi cisco
.
.
.
senthil zoho

Answer

var msg = [{
  "name": "maha",
  "team": "mahendra"
}, {
  "name": "vengi",
  "team": "cisco"
}, {
  "name": "anish",
  "team": "goldman"
}, {
  "name": "VP",
  "team": "deloitte"
}, {
  "name": "senthil",
  "team": "zoho"
}];

for (var data in msg) {
  var row = "<tr>";
  row += "<td>" + msg[data].name + "</td>";
  row += "<td>" + msg[data].team + "</td>";
  row += "</tr>";
  $("#myTable").append(row);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
  <thead>
    <th>Name</th>
    <th>team</th>
  </thead>
  <tbody id="myTable">
  </tbody>
</table>