2016-05-17 90 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 
      }); 
     }); 
    } 

希望它可以幫助