Javascript Angular ng grid:如何加载多个api数据?

Javascript Angular ng grid:如何加载多个api数据?,javascript,php,jquery,angularjs,Javascript,Php,Jquery,Angularjs,我有一个“ng grid”表,它有两种类型的数据源。一个来自我的数据库,使用一个名为getContributors()的函数,另一个来自api列表 getContractors函数类似于ng grid教程中的默认函数 function getContributors() { var deferred = $q.defer(); $http.get(contributorsFile)

我有一个“ng grid”表,它有两种类型的数据源。一个来自我的数据库,使用一个名为getContributors()的函数,另一个来自api列表

getContractors函数类似于ng grid教程中的默认函数

            function getContributors() {
                var deferred = $q.defer();

                $http.get(contributorsFile)
                    .then(function(result) {
                        contributors = result.data;
                        deferred.resolve(contributors);
                    }, function(error) {
                        deferred.reject(error);
                    });

                return deferred.promise;
            }
我加载多个api数据的方法是首先加载数据库数据,然后在所有数据库数据加载完毕后,它将使用数据库数据中的参数向api发出请求

                    var ajax_wait_count = 0;

                gridService.getContributors().then(function(data) {
// Looping each data with angular.forEach()
                    angular.forEach(data, function(value, key){
                        var this_uid = value['uid'];

    //                  if(ajax_wait_count==0)
    //                  {
                            $timeout(function(){
                                $.ajax({
                                    url: "<?php echo $glob_base_url; ?>api/getrank.php",
                                    type: 'POST',
                                    data: { id: this_uid },
                                    dataType: 'json', // Notice! JSONP <-- P (lowercase)
                                    success: function (json) {
                                        // do stuff with json (in this case an array)
    //                            json = jQuery.parseJSON(json);
                                        data[key]['ranked_tier'] = json;
    //                            console.log(json);
                                    },
                                    error: function () {
    //                            alert("Error");
                                    }
                                });

                                $.ajax({
                                    url: "<?php echo $glob_base_url; ?>api/getlevel.php",
                                    type: 'POST',
                                    data: { id: this_uid },
                                    dataType: 'json', // Notice! JSONP <-- P (lowercase)
                                    success: function (json) {
                                        // do stuff with json (in this case an array)
    //                            json = jQuery.parseJSON(json);
                                        data[key]['level'] = json['level'];
    //                            console.log(json);
                                    },
                                    error: function () {
    //                            alert("Error");
                                    }
                                });

                                $.ajax({
                                    url: "<?php echo $glob_base_url; ?>api/getsummonercreate.php",
                                    type: 'POST',
                                    data: { id: this_uid },
                                    dataType: 'json', // Notice! JSONP <-- P (lowercase)
                                    success: function (json) {
                                        // do stuff with json (in this case an array)
    //                            json = jQuery.parseJSON(json);
                                        if (json != 0) {
                                            var date_c = json[0]['create_date'];
                                            date_c = date_c.replace(' ', 'T');
                                            new_date = new Date(date_c);
    //                            console.log(json);
                                            var datestring = new_date.format("yyyy-mm-dd HH:MM:ss");
                                            data[key]['summoner_create_date'] = datestring;
                                        }
                                        else if (json == 0) {
                                            data[key]['summoner_create_date'] = "";
                                        }
                                    },
                                    error: function () {
    //                            alert("Error");
                                    }
                                });

                                $.ajax({
                                    url: "<?php echo $glob_base_url; ?>api/getlastplayed.php",
                                    type: 'POST',
                                    data: { id: this_uid },
                                    dataType: 'json', // Notice! JSONP <-- P (lowercase)
                                    success: function (json) {
                                        // do stuff with json (in this case an array)
    //                            json = jQuery.parseJSON(json);
                                        if (json != "null" && json != null) {
                                            var datedatas = json;
                                            var datearray = [];
                                            var thedatestr = "";
                                            var loopidx = 1;

                                            now_date = new Date();
                                            now_date.setHours(0);
                                            now_date.setMinutes(0);
                                            now_date.setSeconds(0);

                                            now_date.setDate(now_date.getDate() - 2);

                                            next_date = new Date();
                                            next_date.setHours(23);
                                            next_date.setMinutes(59);
                                            next_date.setSeconds(59);

    //                                next_date.setDate(next_date.getDate());

                                            angular.forEach(datedatas, function (value3, key3) {
                                                datearray[key3] = parseInt(value3['createDate']);
                                            });
                                            datearray.sort();
                                            datearray.reverse();

                                            var count_played_today = 0;

                                            angular.forEach(datearray, function (value2, key2) {
                                                if (loopidx == 1) {
                                                    thedatestr = value2;
                                                }

                                                date_compare = new Date(parseInt(value2));

                                                if (date_compare.getTime() >= now_date.getTime() && date_compare.getTime() < next_date.getTime()) {
                                                    count_played_today++;
                                                }


                                                loopidx++;
                                            });

    //                                var date_c = json[0]['create_date'];
    //                                date_c = date_c.replace(' ','T');
                                            var dateinsert = parseInt(thedatestr);
                                            new_date = new Date(dateinsert);
    //                            console.log(json);
                                            var datestring = new_date.format("yyyy-mm-dd HH:MM:ss");
                                            data[key]['last_played_date'] = datestring;

                                            this_date = new Date();

                                            date_diff = dateDiff(new_date.toString(), this_date.toString());

                                            data[key]['last_played_date_qty'] = date_diff.d + " days " + date_diff.h + " hours " + date_diff.m + " minutes";
                                            data[key]['count_played'] = count_played_today;
                                        }
                                        else if (json == "null" || json == null) {
                                            data[key]['last_played_date'] = "";
                                            data[key]['last_played_date_qty'] = "";
                                            data[key]['count_played'] = 0;
                                        }
                                    },
                                    error: function () {
    //                            alert("Error");
                                    }
                                });
                            },1500);
                            ajax_wait_count=0;
    //                  }

                        ajax_wait_count++;
                    });
                    $scope.myData = data;
                });
var ajax\u wait\u count=0;
gridService.getContributors().then(函数(数据){
//使用angular.forEach()循环每个数据
角度.forEach(数据、函数(值、键){
var this_uid=value['uid'];
//if(ajax\u wait\u count==0)
//                  {
$timeout(函数(){
$.ajax({
url:“api/getrank.php”,
键入:“POST”,
数据:{id:this_uid},
数据类型:'json',//注意!JSONP