Data Structure
var X = {
a: [{name:"john", phone:777},{name:"john", phone:777},{name:"john", phone:777}],
b: [{name:"john", phone:777},{name:"john", phone:777},{name:"john", phone:777}],
c: [{name:"john", phone:777},{name:"john", phone:777},{name:"john", phone:777}],
d: [{name:"john", phone:777},{name:"john", phone:777},{name:"john", phone:777}]
}
Function
function showTable(trnum,X,a) {
var Tablecode = "<table><tbody>";
for (var i=0; i< X.a.length;i++) {
for (var j=0; j< trnum; j++) {
Tablecode += "<tr><td>"+X.a[i].name+"</td><td>"+X.a[i].phone+"</td></tr>";
}
}
Tablecode += "</tbody></table>";
$("#elem").append(Tablecode);
}
Markup
<body>
<button onclick="showTable(4,X,"a");"></button>
<div id="elem">
</div>
</body>
I'm trying to output data to table according to letter. one object on one table row.(all objects in table within one letter). this code doesn't work- unexpected token "}"
. oddly enough, it points to <div id="elem">
line. but there's no such character! How can I fix this?
UPDATE: thanks, error disappeared... but it outputs the whole structure, how do I make it output only 'a' objects?