Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng重复和搜索筛选器结果导致的无限循环_Javascript_Arrays_Angularjs - Fatal编程技术网

Javascript ng重复和搜索筛选器结果导致的无限循环

Javascript ng重复和搜索筛选器结果导致的无限循环,javascript,arrays,angularjs,Javascript,Arrays,Angularjs,返回以下搜索结果后: [ { "id": 0, "name": "UserManagement", "parent": "modules", "grandpa": "non", "viewname": "User Management", "level": "module", "template": "UserManagement", "keywords": "user management users manager mana

返回以下搜索结果后:

[
  {
    "id": 0,
    "name": "UserManagement",
    "parent": "modules",
    "grandpa": "non",
    "viewname": "User Management",
    "level": "module",
    "template": "UserManagement",
    "keywords": "user management users manager managing ",
    "description": "module UserManagement My goal is simple. It is a complete understanding of the universe, why it is as it is and why it exists at all . Stephen Hawking",
    "partitions": {

    }
},
{
    "id": 1,
    "name": "UsersRoles",
    "viewname": "Users Roles",
    "level": "partition",
    "parent": "UserManagement",
    "grandpa": "modules",
    "template": "UsersRoles",
    "keywords": "users roles accounts ",
    "description": "partition UsersRoles The black hole information paradox is a puzzle resulting from the combination of quantum mechanics and general relativity",
    "usecases": {

    }
},
{
    "id": 2,
    "name": "Login",
    "viewname": "Log in",
    "level": "usecase",
    "parent": "UsersRoles",
    "grandpa": "UserManagement",
    "template": "Login",
    "keywords": "log in",
    "description": " usecase login black hole information paradox"
},
{
    "id": 3,
    "name": "EditProfile",
    "viewname": "Edit Profile",
    "level": "usecase",
    "parent": "UsersRoles",
    "grandpa": "UserManagement",
    "template": "EditProfile",
    "keywords": "edit profile",
    "description": "usecase editprofile black hole information paradox"
},
{
    "id": 7,
    "name": "Accounting",
    "parent": "modules",
    "grandpa": "non",
    "viewname": "Accounting",
    "level": "module",
    "template": "Accounting",
    "keywords": "accounts",
    "description": "module accounting My goal is simple. It is a complete understanding of the universe, why it is as it is and why it exists at all . Stephen Hawking",
    "partitions": {                        
    }
},
{
    "id": 10,
    "name": "NewFiscalRecord",
    "viewname": "New Fiscal Record",
    "level": "usecase",
    "parent": "AccountsAndFiscalRecords",
    "grandpa": "Accounting",
    "template": "NewFiscalRecord",
    "keywords": "NewFiscalRecord",
    "description": "usecase new fiscal record"
},
{
    "id": 11,
    "name": "FiscalReports",
    "viewname": "Fiscal Reports",
    "level": "partition",
    "parent": "Accounting",
    "grandpa": "modules",
    "template": "FiscalReports",
    "keywords": "FiscalReports",
    "description": "partition Fiscal Reports",
    "usecases": {
    }
}
var nest = function (seq, keys) {
        //console.log(keys.length)
        if (!keys.length)
            return seq;
        var first = keys[0];
        var rest = keys.slice(1);
        return _.mapValues(_.groupBy(seq, first), function (value) {
            return nest(value, rest)
        });
    };
var nested = nest(result, ['grandpa','parent']);            
] 为了按“爷爷”和“家长”属性对结果进行分组,我使用了lodash.js,如下所示:

[
  {
    "id": 0,
    "name": "UserManagement",
    "parent": "modules",
    "grandpa": "non",
    "viewname": "User Management",
    "level": "module",
    "template": "UserManagement",
    "keywords": "user management users manager managing ",
    "description": "module UserManagement My goal is simple. It is a complete understanding of the universe, why it is as it is and why it exists at all . Stephen Hawking",
    "partitions": {

    }
},
{
    "id": 1,
    "name": "UsersRoles",
    "viewname": "Users Roles",
    "level": "partition",
    "parent": "UserManagement",
    "grandpa": "modules",
    "template": "UsersRoles",
    "keywords": "users roles accounts ",
    "description": "partition UsersRoles The black hole information paradox is a puzzle resulting from the combination of quantum mechanics and general relativity",
    "usecases": {

    }
},
{
    "id": 2,
    "name": "Login",
    "viewname": "Log in",
    "level": "usecase",
    "parent": "UsersRoles",
    "grandpa": "UserManagement",
    "template": "Login",
    "keywords": "log in",
    "description": " usecase login black hole information paradox"
},
{
    "id": 3,
    "name": "EditProfile",
    "viewname": "Edit Profile",
    "level": "usecase",
    "parent": "UsersRoles",
    "grandpa": "UserManagement",
    "template": "EditProfile",
    "keywords": "edit profile",
    "description": "usecase editprofile black hole information paradox"
},
{
    "id": 7,
    "name": "Accounting",
    "parent": "modules",
    "grandpa": "non",
    "viewname": "Accounting",
    "level": "module",
    "template": "Accounting",
    "keywords": "accounts",
    "description": "module accounting My goal is simple. It is a complete understanding of the universe, why it is as it is and why it exists at all . Stephen Hawking",
    "partitions": {                        
    }
},
{
    "id": 10,
    "name": "NewFiscalRecord",
    "viewname": "New Fiscal Record",
    "level": "usecase",
    "parent": "AccountsAndFiscalRecords",
    "grandpa": "Accounting",
    "template": "NewFiscalRecord",
    "keywords": "NewFiscalRecord",
    "description": "usecase new fiscal record"
},
{
    "id": 11,
    "name": "FiscalReports",
    "viewname": "Fiscal Reports",
    "level": "partition",
    "parent": "Accounting",
    "grandpa": "modules",
    "template": "FiscalReports",
    "keywords": "FiscalReports",
    "description": "partition Fiscal Reports",
    "usecases": {
    }
}
var nest = function (seq, keys) {
        //console.log(keys.length)
        if (!keys.length)
            return seq;
        var first = keys[0];
        var rest = keys.slice(1);
        return _.mapValues(_.groupBy(seq, first), function (value) {
            return nest(value, rest)
        });
    };
var nested = nest(result, ['grandpa','parent']);            
并将“嵌套”返回到ng repeat内的视图, “嵌套”是“搜索”筛选器返回的内容:

<div ng-repeat="node in filteredModules = (modules | searchFor:searchString track by $index">    
    {{node.name}}    
</div>

{{node.name}
但是它导致了这个问题,我不知道为什么

错误:[$rootScope:infdig]已达到10$digest()次迭代。流产! 观察者在过去5次迭代中被解雇:[[{“msg”:“fn:regulatedinterceptexpression”,“newVal”:119,“oldVal”:115}],{“msg”:“fn:regulatedinterceptexpression”,“newVal”:123,“oldVal”:119}],{“msg”:“fn:regulatedinterceptexpression”,“newVal”:131,“oldVal”:127}],{“msg”:“fn:regulatedinterceptedexpression”,“newVal”:135,“oldVal”:131}]]

注意:当我将结果返回到视图而不对数据进行分组时,不会导致该问题。当在控制台中打印“嵌套”而不在视图上查看时,它工作良好,不会导致错误。 这里试图解释更多:


编辑:是否有其他方法按“爷爷”和“家长”属性对结果进行分组?

我也遇到过这种情况

对我来说,解决这个问题的方法是从js脚本文件中过滤,而不在ng repeat标记中执行过滤操作

因此,在您的情况下,解决方案可能是在控制器中创建一个过滤函数,该函数将在每次触发$scope时为其分配一个排序数组。然后,从ng repeat开始,在整个数组中迭代

编辑:

问题是每次都要创建一个新数组,因此angular需要跟踪它。据我所知,ng repeat运行,然后立即再次检查其集合,以查看在该循环中是否有任何更改。因为函数返回一个新数组,这被视为更改

摘自:
我也遇到过这种情况

对我来说,解决这个问题的方法是从js脚本文件中过滤,而不在ng repeat标记中执行过滤操作

因此,在您的情况下,解决方案可能是在控制器中创建一个过滤函数,该函数将在每次触发$scope时为其分配一个排序数组。然后,从ng repeat开始,在整个数组中迭代

编辑:

问题是每次都要创建一个新数组,因此angular需要跟踪它。据我所知,ng repeat运行,然后立即再次检查其集合,以查看在该循环中是否有任何更改。因为函数返回一个新数组,这被视为更改

摘自:

那么,您对发生的情况和导致错误的原因有什么解释吗@JRoller@HalaElBarchah请查看我的编辑,其中解释了此错误的原因同意,尝试调试复杂的角度表达式是一场艰苦的战斗,使用javascript执行逻辑并尽可能简单地重复ng是一种更明智的方法。那么,您有什么解释吗对发生的情况和导致错误的原因进行详细说明@JRoller@HalaElBarchah请查看我解释此错误原因的编辑同意,尝试调试复杂的角度表达式是一场艰苦的战斗,使用javascript执行逻辑并尽可能简单地重复ng是一种更明智的方法