Javascript forEach(函数(数据),其中响应是json双dimensional

Javascript forEach(函数(数据),其中响应是json双dimensional,javascript,php,Javascript,Php,原来我有这个, 在我的php控制器中,我有一个返回Javascript中url变量的函数,下一步: /*$datos is an array like this: array:2976 [ 0 => {#1827 +"date": "2018-08-01" +"time": "00:00:00" } 1 => {#1828 +"date": "2018-08-01" +"time": "00:15

原来我有这个,

在我的php控制器中,我有一个返回Javascript中url变量的函数,下一步:

/*$datos is an array like this:
array:2976 [
    0 => {#1827
        +"date": "2018-08-01"
        +"time": "00:00:00"
    }
    1 => {#1828
        +"date": "2018-08-01"
        +"time": "00:15:00"
    }]
*/

return response()->json($datos);
然后在Javascript中,我使用返回url:

console.log显示:

    {fecha: "2018-08-01", hora: "00:00:00"}
    {fecha: "2018-08-01", hora: "00:15:00"}
这很好,但是现在,在php中,我必须像这样将两个JSON放在一起:

$datos = array(response()->json($datos_a), response()->json($datos_b));
return response()->json($datos);
// PHP
$datos = [$datos_a, $datos_b];
return response()->json($datos);

// JS
$.get(url, function(response) {
  response.forEach(function(dataSet) {
    dataSet.forEach(function(data) {
      console.log(data);
    }
  });
});
$datos_a和$datos_b类似于示例的第一个数组

那么,如何在javascript中循环新的响应呢?我期待类似于:

$.get(url, function(response){
    response["0"].forEach(function(data){
        console.log(data);}
    response["1"].forEach(function(data){
        console.log(data);}

当然这是错误的,但我对所有的数组、json结构都感到困惑。

试试这样的方法:

$datos = array(response()->json($datos_a), response()->json($datos_b));
return response()->json($datos);
// PHP
$datos = [$datos_a, $datos_b];
return response()->json($datos);

// JS
$.get(url, function(response) {
  response.forEach(function(dataSet) {
    dataSet.forEach(function(data) {
      console.log(data);
    }
  });
});
基本上,通过您的尝试:

$datos = array(response()->json($datos_a), response()->json($datos_b));
return response()->json($datos);

…每个数据集对数据进行两次JSON编码,然后是最后一次。您只需对要返回输出的最终值进行编码。

谢谢,我尝试了arraydatos_a、datos_b,但没有使用2 foreach循环。