Hi guys ,
I was wandering if I could get abit of help with understanding how to push html code into an array. I cant seem to find any article out there that explains this.
I'm trying to construct a table based on values I get from my data.d.results object. what I would like to do is to contruct the html in the array before I then display on the page
<style type="text/css" scoped>
table.GeneratedTable {
width:100%;
background-color:#FFFFFF;
border-collapse:collapse;border-width:1px;
border-color:#336600;
border-style:solid;
color:#009900;
}
table.GeneratedTable td, table.GeneratedTable th {
border-width:1px;
border-color:#336600;
border-style:solid;
padding:3px;
}
table.GeneratedTable thead {
background-color:#CCFF99;
}
</style><!-- HTML Code --><table class="GeneratedTable"><thead><tr><th>Header Cell 1</th><th>Header Cell 2</th><th>Header Cell 3</th></tr></thead><tbody><tr><td>Row 1, Cell 1</td><td>Row 1, Cell 2</td><td>Row 1, Cell 3</td></tr><tr><td>Row 2, Cell 1</td><td>Row 2, Cell 2</td><td>Row 2, Cell 3</td></tr><tr><td>Row 3, Cell 1</td><td>Row 3, Cell 2</td><td>Row 3, Cell 3</td></tr></tbody></table>this is the table above that I would like to reconstruct an put into the array like what I have below
var htmlTest = [];
htmlText.Push("<table class="GeneratedTable"><thead><tr><th>Title</th><th>FirstName</th><th>Company</th></tr></thead><tbody>"); for (var i = 0; i < data.d.results.length; i++) { var items = data.d.results[i]; var myTitle = items.Title; var myFirstName = items.FirstName; var myCompany = items.Company; htmlText.Push("<tr><td>' + myTitle + ' </td><td>' + myFirstName + '</td><td>' + myCompany + '</td></tr>"); } htmlText.Push("</tbody></table>"); $(".GeneratedTable").html(htmlText.join(''));
but it doesn't seem to work. I'm not really sure whether I'm missing some quotes or my concatenation is really bad. A little bit of help understanding this generally would be nice to also enable me continue my learning process.
thanks