2016-05-17 51 views
1

我用PHP函数array_chunk分割一个大数组,然后使用json_encode将结果数组转换为json。我的回答是这样的:在分块数组中访问数据

[["nombre","apellido","flor","animal","ciudad","cosa"],["nombre","apellido","flor","animal","ciudad","cosa"],["nombre","apellido","flor","animal","ciudad","cosa"]] 

现在,我想通过AJAX数组的数组,并把每一个项目在一个表中的列。

通常情况下,如果我只是得到一个单一的阵列,我做这样的事情:

//rest of the ajax function... 
success: function(data) { 
$("#resultados").append("<tr><td>"+data[0]+"</td><td>"+data[1]+"</td><td>"+data[2]+"</td><td>"+data[3]+"</td><td>"+data[4]+"</td><td>"+data[5]+"</td><td>"+data[6]+"</td><td>"+data[7]+"</td><td>"+data[8]+"</td><td>"+data[9]+"</td><td>"+data[10]+"</td></tr>"); 
} 

其中“resultados”是一个表行的ID。

我想把每个数组的数据放在不同的表中,所以我如何访问这些数组的索引?

+1

[DEMO](https://fiddle.jshell.net/L1oyc2h2/)这样的 – guradio

回答

0

这可能是这样的

//rest of the ajax function 
    success: function(data){ 
     //we access first array and then inner 
     $.each(data,function(index,value){ 
      // now we access inner arrays 
      $.each(data[index],function(index2,value2){ 
       //here you do what you had to do 
       //data[index][index2] equals value2 
      }); 
     }); 
    } 

希望它可以帮助