Tuesday 15 January 2013

arrays - AngularJS "10 $digest() iterations reached" in Internet Explorer dealing with a custom filter -



arrays - AngularJS "10 $digest() iterations reached" in Internet Explorer dealing with a custom filter -

our project using custom filter provide sorting , filtering of items in list. takes 2 arguments, list, , filter type parameter determines sort/filter scheme apply. filter appears responsible "10 $digest() iterations reached" error in net explorer (only). business end of filter below:

return function(players, filtertype) { switch (filtertype) { case 'money': homecoming players.sort(function (a, b) { if (a.isself) homecoming -1; if (a.winnerprizemoney == b.winnerprizemoney) homecoming 0; if (b.isself || a.winnerprizemoney < b.winnerprizemoney) homecoming -1; if (a.isself || a.winnerprizemoney > b.winnerprizemoney) homecoming 1; homecoming 0; }); case 'tracked players': var trackedplayers = []; (var = 0; < players.length; i++) { if (players[i].istracked || players[i].isself) { trackedplayers.push(players[i]); } } homecoming trackedplayers; case 'connections': var connectedplayers = []; (var j = 0; j < players.length; j++) { if (players[j].isconnected || players[j].isself) { connectedplayers.push(players[j]); } } homecoming connectedplayers; case 'rank': homecoming players.sort(function (a, b) { if (a.isself) homecoming -1; if (a.winnerposition == b.winnerposition) homecoming 0; if (b.isself || a.winnerposition < b.winnerposition) homecoming -1; if (a.isself || a.winnerposition > b.winnerposition) homecoming 1; homecoming 0; }); default: } };

two of filter types sort items, other 2 filter items. problem presents page loads , gets items filter, , filtertype set 'rank'.

i have read array.sort modifies array in place, (i.e. not homecoming new array). understanding on count correct? .sort not cause problem returning same array came in with, items changed in position. applies filtertypes of 'money' , 'rank'.

for 'tracked players' , 'connections' there improve way handle creating new array , pushing specific items according filter? while not appear culprit in instance, seems fit mold others have suggested possible causes in other articles regarding error.

i sense spinning wheels on this, spent 6 hours yesterday ("after work") fiddling trying diagnose , prepare it. have narrowed downwards filtering mechanism above, other that, having no luck.

update

this seems have net explorer. tested filter in chrome , firefox , nail 1 time per filtertype alter (e.g. user changes value of filter dropdown in turn changes filtertype , fires off filter.

internet explorer repeatedly hits filter. , when filtertype = 'rank'. don't though. rank , money have exact same sorting scheme, on different properties.

just sure did not have fact set filtertype = 'rank' in initialization of controller, changed 3 of other values in turn. no problems. seems perchance comparing of values winnerposition (numeric) or value somehow changing on item beingness sorted.

stepping through execution update

ok, may need enlighten me. $watchcollectionwatch function (angular.js:12307 in case) iterates through items in each collection on scope , checks oldvalue (i.e. passed filter in case) newvalue (what came back) if 2 different increments changedetected signaling collection has changed. when collection changes has filter on it, re-runs filter. in case changing ordering of collection , every time filter gets run, reads having changed. how around this?

i ended changing around instead of having filter above registered such app, set on controller called ng-change on drop downwards user specifies filter with.

i changed code little. store players in both $scope.players , $scope.storageplayers. storageplayers holds empirical set of players. $scope.players list of players on page bound to. modify $scope.players , read $scope.storageplayers.

new version $scope.newfilter = function () { switch ($scope.selectedfilter) { case 'money': $scope.players = $scope.storageplayers.sort(function (a, b) { if (a.isself) homecoming -1; if (a.winnerprizemoney == b.winnerprizemoney) homecoming 0; if (b.isself || a.winnerprizemoney < b.winnerprizemoney) homecoming -1; if (a.isself || a.winnerprizemoney > b.winnerprizemoney) homecoming 1; homecoming 0; }); break; case 'tracked players': var trackedplayers = []; (var = 0; < $scope.storageplayers.length; i++) { if ($scope.storageplayers[i].istracked || $scope.storageplayers[i].isself) { trackedplayers.push($scope.storageplayers[i]); } } $scope.players = trackedplayers; break; case 'connections': var connectedplayers = []; (var j = 0; j < $scope.storageplayers.length; j++) { if ($scope.storageplayers[j].isconnected || $scope.storageplayers[j].isself) { connectedplayers.push($scope.storageplayers[j]); } } $scope.players = connectedplayers; break; case 'rank': $scope.players = $scope.storageplayers.sort(function (a, b) { if (a.isself) homecoming -1; if (a.winnerposition == b.winnerposition) homecoming 0; if (b.isself || a.winnerposition < b.winnerposition) homecoming -1; if (a.isself || a.winnerposition > b.winnerposition) homecoming 1; homecoming 0; }); break; default: }

arrays angularjs internet-explorer filter infinite-loop

No comments:

Post a Comment