gpt4 book ai didi

javascript - Angular $摘要错误

转载 作者:行者123 更新时间:2023-12-03 08:15:57 25 4
gpt4 key购买 nike

代码如下:plnkr.co

HTML:

<!DOCTYPE html>
<html ng-app="example">

<head>
<script data-require="jquery@1.11.3" data-semver="1.11.3" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script data-require="angular.js@1.2.28" data-semver="1.2.28" src="https://code.angularjs.org/1.2.28/angular.js"></script>
</head>

<body ng-controller="mainCtrl">
<div ng-repeat="(key, val) in obj | groupPlayers">
{{key}} = {{ val }}
</div>
<script type="text/javascript" src="script.js"></script>
</body>

</html>

脚本.js

(function() {
angular
.module('example', [])

.controller('mainCtrl', function($scope) {
$scope.obj = [
{ lastname: 'Jackson', firstname: 'George', score: 6},
{ lastname: 'Jackson', firstname: 'George', score: 10},
{ lastname: 'Smith', firstname: 'Michael', score: 8},
{ lastname: 'Smith', firstname: 'Amanda', score: 2},
{ lastname: 'Smith', firstname: 'Michael', score: 7},
{ lastname: 'Doe', firstname: 'John', score: 4},
];
})

.filter('groupPlayers', function() {
return function(list, search) {
var group = {};
var key;

angular.forEach(list, function(item) {
key = item.lastname + ' ' + item.firstname;
if(!group[key])
group[key] = [];
group[key].push(item.score);
});

return group;
}
})
;
})();

我想对对象的项目进行分组以按玩家显示得分。我创建了一个 Angular 过滤器来完成这项工作。显示正常,但我在控制台中出现错误,经过一个小时的分析后我没有发现问题!

错误:已达到 10 $digest() 迭代。中止!

谢谢

最佳答案

当使用<div ng-repeat="(key, val) in objFiltered">时和$scope.objFiltered = $filter('groupPlayers')($scope.obj);错误不再发生。

关于javascript - Angular $摘要错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33937595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com