简体   繁体   English

JavaScript多维数组JSON

[英]javascript multidimensional array JSON

I am grabbing data from a mySql DB via PHP and returning it to my javascript as JSON data. 我正在通过PHP从mySql数据库中获取数据,并将其作为JSON数据返回给我的JavaScript。 I want to stuff the returned data...the returned JSON data...into a javascript array: 我想将返回的数据,返回的JSON数据填充到javascript数组中:

var DataArray = new Array();

$.getJSON("php_src/getData.php?rTable="+myTable, function(data) {
    myData = data;

    $.each(myData , function(i,jsonData) {

        var bid = jsonData.user_id;
        $myBidFound = -1;
        for( $i=0; $i<DataArray.length; $i++ )
        {   
            if( DataArray[$i][0].user_id == bid )
            {
                $myBidFound = $i;
                break;
            }
        }
        if( $myBidFound == -1 )
        {
            $myBidFound = bid;
        }
        DataArray[$myBidFound] = new Array(jsonData);
    });
});

Is this the correct way? 这是正确的方法吗?

If you want to cache the results on the client side, try using $.Data() method. 如果要在客户端缓存结果,请尝试使用$.Data()方法。 It will store the results in the DOM. 它将结果存储在DOM中。

I have done it before with the toolTip and it seemed to work nicely. 我以前用toolTip完成过,它似乎工作得很好。

and returning it to my javascript as JSON data 并将其作为JSON数据返回到我的JavaScript

You don't have to do anything else then, just assign a variable to the received data. 然后,您无需执行其他任何操作,只需为接收到的数据分配一个变量。 That's what JSON means. 这就是JSON的意思。

myData should be what you want. myData应该是您想要的。 Try to use it or log it to the console in a console-equipped browser (IE9, Fx, Chrome) 尝试使用它或在配备控制台的浏览器(IE9,Fx,Chrome)中将其记录到控制台

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM