我正试图用JS tablesort对我的表进行排序,JS tablesord用JSON填充,下面的错误出现在我的中
"无法读取未定义"的属性"0"
看起来tablesort无法识别ajax数据。
这是我的jquery
$.get(url, function(response){
serverResponse = response;
for(i in response.content){
totalclientes++;
var status = response.content[i].LojaStatus;
if(status == 0){
LojaStatus = "Ativo";
botao = '' ' +
'<div class = "btn-group"> <button type = "button" class = "btn btn-primary" onclick="redirect(' + response.content[i].LojaId + ')" data-toggle="modal" data-target="#myModal">Editar</button> <button type = "button" class = "btn btn-primary dropdown-toggle" data-toggle = "dropdown"> <span class = "caret"></span> <span class = "sr-only">Toggle Dropdown</span> </button> <ul class = "dropdown-menu" role = "menu"> <li><a href = "javascript:deletar(' + response.content[i].LojaId + ')">Desativar</a></li> <li><a href = "http://amovitrine.devmaker.com.br/relatorioloja.php?LojaId='+ response.content[i].LojaId +'">Relatorio</a></li> </ul> </div>';
}else{
LojaStatus = "Inativo";
botao = '' ' +
'<div class = "btn-group"> <button type = "button" class = "btn btn-primary" onclick="redirect('+response.content[i].LojaId+')" data-toggle="modal" data-target="#myModal">Editar</button> <button type = "button" class = "btn btn-primary dropdown-toggle" data-toggle = "dropdown"> <span class = "caret"></span> <span class = "sr-only">Toggle Dropdown</span> </button> <ul class = "dropdown-menu" role = "menu"> <li><a href = "javascript:ativar('+response.content[i].LojaId+')">Ativar</a></li><li><a href = "http://amovitrine.devmaker.com.br/relatorioloja.php?LojaId='+ response.content[i].LojaId +'">Relatorio</a></li> </ul> </div>';
}
var botao =
data +=''
<tr>'
<td>'+response.content[i].LojaNome+'</td>'
<td>'+response.content[i].LojaBairro+'</td>'
<td>'+response.content[i].LojaTelefone1+'</td>'
<td>'+LojaStatus+'</td>'
<td>'+response.content[i].PlanoNome+'</td>'
<td>'+response.content[i].LojaInicioPlano+'</td>'
<td>'+response.content[i].LojaFimPlano+'</td>'
<td>'+botao+'</td>'
</tr>';
}
$('#corpotabela').empty();
$('#corpotabela').append(data);
这是我的桌子
<table class="table table-bordered table-hover" id="table">
<thead style="border: 1px solid #ddd;" >
<tr style="cursor: pointer;">
<th>Nome</th>
<th>Bairro</th>
<th>Telefone</th>
<th>Status</th>
<th>Plano</th>
<th>Data Inicio</th>
<th>Data Fim</th>
<th>Ações</th>
</tr>
</thead>
<tbody id="corpotabela">
</tbody>
</table>
有什么建议吗?
*编辑这是我现在的桌子
*编辑2
这是我的响应中的对象示例
第3版-解决方案
基本上,我使用的是getData函数之外的表分类器,它填充了我的表。
因此,我在$('#corpotabela').append(data);
行之后应用了表分类器,效果很好。
我建议您检查您得到的响应是否实际上是JSON。然后,尝试使用Firebug来获得具体的错误并将其发布在这里。