【发布时间】:2016-07-31 09:32:04
【问题描述】:
返回搜索结果后如下:
[
{
"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": {
}
}
] 为了按“爷爷”和“父母”属性对结果进行分组,我使用了 lodash.js,如下所示:
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 中的视图, 'nested' 是 'searchFor' 过滤器返回的内容:
<div ng-repeat="node in filteredModules = (modules | searchFor:searchString track by $index">
{{node.name}}
</div>
但它会导致这个问题,我不知道为什么。
错误:[$rootScope:infdig] 达到了 10 个 $digest() 迭代。中止! 观察者在最后 5 次迭代中触发:[[{"msg":"fn:regularInterceptedExpression","newVal":119,"oldVal":115}],[{"msg":"fn:regularInterceptedExpression","newVal" :123,"oldVal":119}],[{"msg":"fn:regularInterceptedExpression","newVal":127,"oldVal":123}],[{"msg":"fn:regularInterceptedExpression"," newVal":131,"oldVal":127}],[{"msg":"fn:regularInterceptedExpression","newVal":135,"oldVal":131}]]
注意:当我将结果返回到视图而不对数据进行分组时,不会导致该问题。并且在控制台中打印“嵌套”而不在视图上查看时,它运行良好并且不会导致错误。 这里试图解释更多:https://jsfiddle.net/qw332bkc/
编辑:还有其他方法可以按“爷爷”和“父母”属性对结果进行分组吗?
【问题讨论】:
标签: javascript arrays angularjs