我需要使用间隔创建一个多维数组。我有 5 个用户,他们的数据每 5 秒增长一次。每个用户都需要数组来保存这些数据,以后每个用户都可以访问这些数据。
currently $rootScope.BHR looks like this:
[1,2,3,4,5,6,7,8,9,10...] <--after 10 secs/ 2 intervals
I want this <--after 10 sec/2 intervals
[1,6..] //key0
[2,7..] //key1
[3,8..] //key2
[4,9..] //key3
[5,10..]//key5
//代码
var liveDataCtrl = angular.module("xo").controller("liveDataCtrl", ["$scope", "$rootScope", "$http", "$interval", "lodash",
function ($scope, $rootScope, $http, $interval, lodash) {
$rootScope.BHR = [];
function shout() {
$http.get("URL")
.then(function (live) {
$scope.live = live.data;
var key;
for (key in $scope.live) {
console.log($scope.live[key].personnelID, "keys");
var getId = $scope.live[key].personnelID;
$http.get(URL + getId)
.then(function (all) {
var data = all.data[0].HR;
console.log(all.data[0].HR);
$rootScope.BHR.push(data);
})
}
})
}
$interval(shout, 5000);
function hrLive() {
console.log($rootScope.BHR, "SHOUT");
}
$interval(hrLive, 5000);
}]);