Javascript 使用Angular Meteor、PublishComposite和Collection助手的无限摘要循环错误
我正试图通过以下两个软件包获得angular meteor的相关数据: 流星收集助手: 流星发布组合: 我的设置如下所示:Javascript 使用Angular Meteor、PublishComposite和Collection助手的无限摘要循环错误,javascript,angularjs,meteor,Javascript,Angularjs,Meteor,我正试图通过以下两个软件包获得angular meteor的相关数据: 流星收集助手: 流星发布组合: 我的设置如下所示: // persistent instance cache this.teamsMap = []; this.helpers({ teams() { const members = People.find({}).fetch(); members.forEach(member => { this.tea
// persistent instance cache
this.teamsMap = [];
this.helpers({
teams() {
const members = People.find({}).fetch();
members.forEach(member => {
this.teamsMap[member._id] = member.teams.map(team => Teams.findOne(team));
});
}
});
model/groups.js
server/groups.js
client/matches/controller/scores.ng.js
client/matches/views/scores.ng.html
发布/订阅部分工作正常,我可以通过控制台获取所有组和相关用户,但只要添加“user in group.usersByScore()”,我就会发现很多错误:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":29,"oldVal":26}],[{"msg":"fn: regularInterceptedExpression","newVal":32,"oldVal":29}],[{"msg":"fn: regularInterceptedExpression","newVal":35,"oldVal":32}],[{"msg":"fn: regularInterceptedExpression","newVal":38,"oldVal":35}],[{"msg":"fn: regularInterceptedExpression","newVal":41,"oldVal":38}]]
http://errors.angularjs.org/1.4.2/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22ms…rInterceptedExpression%22%2C%22newVal%22%3A41%2C%22oldVal%22%3A38%7D%5D%5D
at REGEX_STRING_REGEXP (angular.js:68)
at Scope.$get.Scope.$digest (angular.js:15723)
at Scope.$get.Scope.$apply (angular.js:15953)
at safeApply (angular-meteor-meteorCollection.js:154)
at Object.angularMeteorCollections.factory.AngularMeteorCollection.updateCursor.self.observeHandle.cursor.observe.addedAt (angular-meteor-meteorCollection.js:174)
at LocalCollection._observeFromObserveChanges.observeChangesCallbacks.addedBefore (observe.js:96)
at Object.LocalCollection._CachingChangeObserver.self.applyChange.addedBefore (observe.js:33)
at minimongo.js:373
at _.extend.runTask (fiber_stubs_client.js:42)
at _.extend.flush (fiber_stubs_client.js:70)
Exception in queued task: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":29,"oldVal":26}],[{"msg":"fn: regularInterceptedExpression","newVal":32,"oldVal":29}],[{"msg":"fn: regularInterceptedExpression","newVal":35,"oldVal":32}],[{"msg":"fn: regularInterceptedExpression","newVal":38,"oldVal":35}],[{"msg":"fn: regularInterceptedExpression","newVal":41,"oldVal":38}]]
http://errors.angularjs.org/1.4.2/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22ms…rInterceptedExpression%22%2C%22newVal%22%3A41%2C%22oldVal%22%3A38%7D%5D%5D
at REGEX_STRING_REGEXP (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:98:12)
at Scope.$get.Scope.$digest (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:15753:19)
at Scope.$get.Scope.$apply (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:15983:24)
at safeApply (http://localhost:3000/packages/urigo_angular.js?3cfbb5ec69330c7589d9a07bff661ca2dd28d04d:1173:47)
at Object.angularMeteorCollections.factory.AngularMeteorCollection.updateCursor.self.observeHandle.cursor.observe.addedAt (http://localhost:3000/packages/urigo_angular.js?3cfbb5ec69330c7589d9a07bff661ca2dd28d04d:1193:11)
at LocalCollection._observeFromObserveChanges.observeChangesCallbacks.addedBefore (http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:3862:28)
at Object.LocalCollection._CachingChangeObserver.self.applyChange.addedBefore (http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:3799:56)
at http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:415:13
at _.extend.runTask (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:693:11)
at _.extend.flush (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:721:10)
感谢您的帮助。发生这种情况的原因是
usersByScore()
每次调用函数时都返回一个新的对象实例。因此,摘要循环认为对象在不断更新,并放弃以避免被卡住
目前,我一直在解决同一个问题,所以我还不知道如何解决它
编辑:对这个问题进行了相当广泛的研究后,我不得不得出结论,如果不对角流星进行重大修改,这是不可能实现的。我也有类似的问题。ng repeat循环中集合文档的集合帮助器调用导致摘要循环 在我的情况下,我收集了多个团队中每个人的人员(人员文档上的团队ID数组) 在对这个问题进行调查后,我得出了与@mpkorstanje类似的结论。最后,我发现自己在客户端应用程序中实现了一个AngularMeteor助手,并放弃了本例中的收集助手 我的angular meteor助手实现如下所示:
// persistent instance cache
this.teamsMap = [];
this.helpers({
teams() {
const members = People.find({}).fetch();
members.forEach(member => {
this.teamsMap[member._id] = member.teams.map(team => Teams.findOne(team));
});
}
});
以及控制器功能,用于访问视图中人员的团队:
getTeams(member) {
return this.teamsMap[member._id];
}
通过这个实现,反应性和视图绑定可以按预期工作,我没有得到摘要循环。不幸的是,它有一种令人讨厌的味道。希望它能帮助别人解决问题
angular.module('tippo').config(['$urlRouterProvider', '$stateProvider', '$locationProvider',
function($urlRouterProvider, $stateProvider, $locationProvider){
$locationProvider.html5Mode(true);
$stateProvider.state('scores', {
url: '/scores',
templateUrl: 'client/matches/views/scores.ng.html',
controller: 'ScoresController',
resolve: {
'subscribe': ['$meteor', function($meteor) {
return $meteor.subscribe('groupsWithUsers');
}],
"currentUser": ["$meteor", function($meteor){
return $meteor.requireUser();
}]
}
});
}
]);
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":29,"oldVal":26}],[{"msg":"fn: regularInterceptedExpression","newVal":32,"oldVal":29}],[{"msg":"fn: regularInterceptedExpression","newVal":35,"oldVal":32}],[{"msg":"fn: regularInterceptedExpression","newVal":38,"oldVal":35}],[{"msg":"fn: regularInterceptedExpression","newVal":41,"oldVal":38}]]
http://errors.angularjs.org/1.4.2/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22ms…rInterceptedExpression%22%2C%22newVal%22%3A41%2C%22oldVal%22%3A38%7D%5D%5D
at REGEX_STRING_REGEXP (angular.js:68)
at Scope.$get.Scope.$digest (angular.js:15723)
at Scope.$get.Scope.$apply (angular.js:15953)
at safeApply (angular-meteor-meteorCollection.js:154)
at Object.angularMeteorCollections.factory.AngularMeteorCollection.updateCursor.self.observeHandle.cursor.observe.addedAt (angular-meteor-meteorCollection.js:174)
at LocalCollection._observeFromObserveChanges.observeChangesCallbacks.addedBefore (observe.js:96)
at Object.LocalCollection._CachingChangeObserver.self.applyChange.addedBefore (observe.js:33)
at minimongo.js:373
at _.extend.runTask (fiber_stubs_client.js:42)
at _.extend.flush (fiber_stubs_client.js:70)
Exception in queued task: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":29,"oldVal":26}],[{"msg":"fn: regularInterceptedExpression","newVal":32,"oldVal":29}],[{"msg":"fn: regularInterceptedExpression","newVal":35,"oldVal":32}],[{"msg":"fn: regularInterceptedExpression","newVal":38,"oldVal":35}],[{"msg":"fn: regularInterceptedExpression","newVal":41,"oldVal":38}]]
http://errors.angularjs.org/1.4.2/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22ms…rInterceptedExpression%22%2C%22newVal%22%3A41%2C%22oldVal%22%3A38%7D%5D%5D
at REGEX_STRING_REGEXP (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:98:12)
at Scope.$get.Scope.$digest (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:15753:19)
at Scope.$get.Scope.$apply (http://localhost:3000/packages/angular_angular.js?c3a778493846e58a63e652cd68b47914889a794c:15983:24)
at safeApply (http://localhost:3000/packages/urigo_angular.js?3cfbb5ec69330c7589d9a07bff661ca2dd28d04d:1173:47)
at Object.angularMeteorCollections.factory.AngularMeteorCollection.updateCursor.self.observeHandle.cursor.observe.addedAt (http://localhost:3000/packages/urigo_angular.js?3cfbb5ec69330c7589d9a07bff661ca2dd28d04d:1193:11)
at LocalCollection._observeFromObserveChanges.observeChangesCallbacks.addedBefore (http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:3862:28)
at Object.LocalCollection._CachingChangeObserver.self.applyChange.addedBefore (http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:3799:56)
at http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:415:13
at _.extend.runTask (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:693:11)
at _.extend.flush (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:721:10)
// persistent instance cache
this.teamsMap = [];
this.helpers({
teams() {
const members = People.find({}).fetch();
members.forEach(member => {
this.teamsMap[member._id] = member.teams.map(team => Teams.findOne(team));
});
}
});
getTeams(member) {
return this.teamsMap[member._id];
}