未捕获的RangeError:超出了最大调用堆栈大小。jstree

ant*_*oom 3 javascript arrays jstree angularjs

我收到此错误,不知道如何解决

未捕获的RangeError:超出最大调用堆栈大小

我正在尝试使用jstree lib构建树。数据来自两个不同的http调用。我得到这样的初始数据:

           $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();
Run Code Online (Sandbox Code Playgroud)

console.log返回数组,现在一切都很好。然后我使用函数加载将两个数组合并为一个超级数组

    $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))
        }
Run Code Online (Sandbox Code Playgroud)

如您所见,我尝试通过两种方法获得一个数组,两种方法也都可以工作,并且得到了该数组

  [{
"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
  }]
Run Code Online (Sandbox Code Playgroud)

按照逻辑jstree文档,我的树应该看起来像

* Folder (root) 
---- * Child Folder (parent)
     ---- * Filter 1 (Child)
     ---- * Filter 4 (Child)
Run Code Online (Sandbox Code Playgroud)

但是相反,我得到的错误是某处迭代太多。有人可以帮我找到我的错误吗?先感谢您。柱塞已连接

Ada*_*dam 5

您的数组包含两个带有“ id”:2的项目,其中之一具有定义为“ id”:2的父项。那可能正在创建一个循环引用。

尝试将您的第一个子项目的id更改为4,我在您的代码链接和树上加载了该代码,就像您要找的一样。