My goal is to arrange database data by their groupID
(each with a different groupID
in a separate sub-array). However, when I attempt to push the data into an array, I encounter the following error:
TypeError: Cannot read property 'push' of undefined
at app.js:30
at angular.min.js:136
at m.$digest (angular.min.js:147)
at m.$apply (angular.min.js:151)
at l (angular.min.js:103)
at s (angular.min.js:108)
at XMLHttpRequest.y.onload (angular.min.js:109) "Possibly unhandled rejection: {}"
The code I am using is:
$scope.tasks = [[]];
var temp = [];
var k = 0;
$scope.tempTasks = response.data;
for (var i = 0; $scope.tempTasks[i]; i++) {
if (k > 0) {
$scope.tasks.push( [] );
}
$scope.tasks[k].push($scope.tempTasks[k]);
for (var j = 0; j < $scope.tempTasks.length; j++){
if($scope.tempTasks[i].groupID == $scope.tempTasks[j].groupID){
$scope.tasks[i].push($scope.tempTasks[j]);
} else {
temp[k] = j;
k++;
continue;
}
}
}
This is how the response
appears:
data: Array(7)
0: {ID: 2, Title: "Don't do it", Description: "Just don't do it!", Date: "2018-01-10", groupID: 1}
1: {ID: 3, Title: "Do it", Description: "Just do it", Date: "1999-12-31", groupID: 3}
2: {ID: 4, Title: "asd", Description: "asd", Date: "2000-10-10", groupID: 2}
3: {ID: 6, Title: "jnjkhjkkjh", Description: "jihjuiuiu", Date: "78-9809-99", groupID: 3}
4: {ID: 7, Title: "asdasd", Description: "asdasdasd", Date: "2000-10-10", groupID: 4}
5: {ID: 12, Title: "asd", Description: "asd", Date: "2000-10-10", groupID: 4}
6: {ID: 13, Title: "asd", Description: "asd", Date: "2000-10-10", groupID: 2}