name
name

Reputation: 59

how to fill out the table in Jade

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

Answers (1)

Maxim Goncharuk
Maxim Goncharuk

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

Related Questions