我有一个对象数组
[{ name: Test1, phoneNumb: 123, email: abc }, {name: Test2, phoneNumb: 321, email: cba}, ...]
如何在Jade
中填写这些值的表格答案 0 :(得分:1)
如果你使用AngularJS试试这个:
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
在您的控制器中分配项目集合如下:
$scope.items = [{ name: "Test1", phoneNumb: 123, email: "abc" }, {name: "Test2", phoneNumb: 321, email: "cba"}];
如果您不使用AngularJS,请手动重复每个tr
代码。
table
thead
tr
th Name
th Phone number
th Email
tbody
和javascript函数:
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;
}
}