Reputation: 59
I have an array of objects
[{ name: Test1, phoneNumb: 123, email: abc }, {name: Test2, phoneNumb: 321, email: cba}, ...]
how to fill out a table of these values in Jade
Upvotes: 1
Views: 334
Reputation: 1333
If you use AngularJS try this:
table
thead
tr
th Name
th Phone number
th Email
tbody
tr(ng-repeat='item in items')
td item.name
td item.phoneNumb
td item.email
And in your controller assign the items collection like this:
$scope.items = [{ name: "Test1", phoneNumb: 123, email: "abc" }, {name: "Test2", phoneNumb: 321, email: "cba"}];
If you don't use AngularJS repeat each tr
tag manually.
table
thead
tr
th Name
th Phone number
th Email
tbody
and javascript function:
function fillTable() {
var array = [{ name: "Test1", phoneNumb: 123, email: "abc" }, {name: "Test2", phoneNumb: 321, email: "cba"}];
var table = document.getElementById('table');
for(var i = 0; i < array.length; i++) {
var row = table.insertRow();
var name = row.insertCell(0);
var number = row.insertCell(1);
var email = row.insertCell(3);
name.innerHTML = array[i].name;
number.innerHTML = array[i].phoneNumb;
email.innerHTML = array[i].email;
}
}
Upvotes: 1