【发布时间】:2016-01-12 13:31:38
【问题描述】:
我尝试查看其他帖子,但没有人按照我想要的方式帮助我。 我正在构建一个表,我需要用一些数据填充它。这是我的数据(或部分数据):
var vistorias = [
{ data: '15/05/2015', cliente: 'Viceri', prestador: 'Joaquim', tipo: 'Empresarial simples', empresaPrestadora: 'VistGroup', parecer: 'Bom' },
{ data: '10/05/2015', cliente: 'Krupp', prestador: 'Rafael', tipo: 'Maquinas', empresaPrestadora: 'Vistoriers', parecer: 'Execelente' },
{ data: '24/03/2015', cliente: 'Itautec', prestador: 'Thiago', tipo: 'Empresarial simples', empresaPrestadora: 'VistGroup', parecer: 'Bom' }];
这是我的桌子:
<table class="table table-striped table-bordered table-hover" id="sample_1">
<thead>
<tr>
<th>
Data
</th>
<th>
Cliente
</th>
<th>
Prestador
</th>
<th>
Tipo
</th>
<th>
Empresa Prestadora
</th>
<th>
Parecer da Vistoria
</th>
</tr>
</thead>
<tbody id="TabelaVistorias"></tbody>
</table>
这是我现在尝试使用的代码:
$.each(vistorias, function (vistorias) {
var nTr = "<tr>"
nTr += "<td><p>" + vistorias[0] + "</p></td>";
nTr += "<td><p>" + vistorias[1] + "</p></td>";
nTr += "<td><p>" + vistorias[2] + "</p></td>";
nTr += "<td><p>" + vistorias[3] + "</p></td>";
nTr += "<td><p>" + vistorias[4] + "</p></td>";
nTr += "<td><p>" + vistorias[5] + "</p></td>";
nTr += "</tr>";
$(nTr).appendTo('#TabelaVistorias');
});
它们都是$Doc.ready 中的(数据和 JS 代码)。
我知道这很简单,但我做不到。
【问题讨论】:
-
vistorias[0]的预期结果是什么?Properties of object atvistorias[0]` 没有在$.each()中出现迭代? -
我认为 vistorias 是一个对象,因此您应该使用 vistorias.data 除了 [0] 等。但我不确定(所以不讨厌)。
标签: javascript html json html-table