最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught RangeError: Maximum call stack size exceeded. jstree - Stack Overflow

programmeradmin0浏览0评论

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 es 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

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 es 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

Share Improve this question asked Jul 5, 2016 at 18:39 antonyboomantonyboom 1,1812 gold badges17 silver badges47 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

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.

发布评论

评论列表(0)

  1. 暂无评论