How To Include Array Content In Html?
I have this code var users = result.users; // array $('#dialog:ui-dialog').dialog('destroy'); $('#dialog-confirm').dialog({ resizable: false, height: 140, modal: true
Solution 1:
You can use a JS for-in
to loop through it.
<table id='nameTable'>
<tr><td>Initials</td><td>Full Name </td></tr>
</table>
var names = {
"ss": "Sandra Schlichting",
"fn": "Full name"
};
var $table = $('#nameTable');
var row = '';
for (name in names) {
row += '<tr><td>' + name + '</td><td>' + names[name] + '</td></tr>';
}
$table.append(row)
Here's a fiddle : http://jsfiddle.net/exP2b/4/
Solution 2:
functionmakeTable(users) {
var result = '<table><tr><td>Initials</td><td>Full Name</td></tr>\n';
$.each(users, function(index, value) {
result += '<tr><td>' + index + '</td><td>' + value + '</td></tr>\n';
});
result += '</table>';
return (result);
}
alert(makeTable({"ss":"Sandra Schlichting","fn":"Full name"}));
Post a Comment for "How To Include Array Content In Html?"