I get this error and don't know how to resolve it
Uncaught RangeError: Maximum call stack size exceeded
I'm trying to build tree with use jstree lib. The data comes from two different http calls. I'm getting my initial data like this:
$scope.treeFolders = [];
$scope.treeFilters = [];
$scope.tree = [];
var folders = function () {
$http.get("folders.json")
.success(function (res) {
angular.forEach(res, function(parent){
// console.log(parent)
if(!("parent" in parent)){
parent.parent = "#"
}
})
$scope.treeFolders = res
console.log($scope.treeFolders)
});
};
folders();
var filters = function(){
$http.get("child.json")
.success(function (res) {
angular.forEach(res, function(obj){
if(!("parent" in obj)){
// console.log(obj.folderId)
obj.parent = obj.folderId;
}
// console.log(obj)
});
$scope.treeFilters = res;
console.log($scope.treeFilters)
});
};
filters();
console.log returns arrays, for now everything is good. Then I'm using function load to merge two array to one super array
$scope.load = function(){
// method 1
$scope.tree = $scope.treeFolders.concat($scope.treeFilters);
console.log(JSON.stringify($scope.tree))
// method 2
// $scope.treeFolders.forEach(function(item){
// $scope.tree.push(item)
// })
// $scope.treeFilters.forEach(function(item){
// $scope.tree.push(item)
// })
// console.log(JSON.stringify($scope.tree))
}
So as you can see, I tried to get one array with help two methods, both work as well and I get this array
[{
"id":1,
"userId":1,
"createdDt":"2016-06-27T13:05:03.000+0000",
"text":"folder",
"parent":"#"
},{
"id":2,
"parent":1,
"userId":1,
"createdDt":"2016-06-27T13:26:45.000+0000",
"text":"child folder"
},{
"id":2,
"folderId":2,
"folder":{"id":2,"text":"child folder"},
"body":"empty",
"user":{"id":1,"name":"User 1"},
"userId":1,
"createdDt":"2016-06-27T13:05:47.000+0000",
"text":"filter 1",
"parent":2
},{
"id":3,
"folderId":2,
"folder":{"id":2,"text":"child folder"},
"body":"nothing",
"user":{"id":1,"name":"User 1"},
"userId":1,"createdDt":"2016-06-27T13:00:00.000+0000",
"text":"filter 4",
"parent":2
}]
follow by logic jstree docs, my tree should look like
* Folder (root)
---- * Child Folder (parent)
---- * Filter 1 (Child)
---- * Filter 4 (Child)
but instead of this I get the error that somewhere is too much iterations. Could somebody help me find my mistake? Thank you in advance. Plunker has attached
Your array contains two items with "id":2, and one of them has a parent which is defined as "id":2 as well. That's probably creating a circular reference.
Try changing the id of your first child item to 4, I did that on your plunker link and the tree loaded like you were looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With