正要槽流星教程,并希望引进的添加,更新方法和删除功能,所以,我不是直接从客户端得到与Collection.allow做了书面许可,否则...它与方法,我一直运行到流星MongoDB的更新的RangeError
RangeError: Maximum call stack size exceeded
at Object.toString (native)
at isArguments (http://localhost:3000/packages/es5-shim.js?03b82f907286b5353e3a371eb320635a634fc88b:988:12)
at Function.keys (http://localhost:3000/packages/es5-shim.js?03b82f907286b5353e3a371eb320635a634fc88b:1051:13)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:155:20)
at Object.EJSON.clone (http://localhost:3000/packages/ejson.js?5e95dd4b5971d96cb2d3287c54b14d9002f83ab7:528:5)
at http://localhost:3000/packages/ejson.js?5e95dd4b5971d96cb2d3287c54b14d9002f83ab7:529:22
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:157:22)
at Object.EJSON.clone (http://localhost:3000/packages/ejson.js?5e95dd4b5971d96cb2d3287c54b14d9002f83ab7:528:5)
at http://localhost:3000/packages/ejson.js?5e95dd4b5971d96cb2d3287c54b14d9002f83ab7:529:22
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:157:22)
所以这是我的代码:
方法:
Meteor.methods({
addParty: function (party) {
// Make sure the user is logged in before inserting a task
if (!Meteor.userId()) {
throw new Meteor.Error('not-authenticated');
}
party.owner = Meteor.userId();
party.username = Meteor.user().username;
party.createdAt = new Date();
Parties.insert(party);
},
removeParty: function (party) {
// Make sure only the party owner can delete a party
if (party.owner !== Meteor.userId()) {
throw new Meteor.Error('not-authorized');
}
Parties.remove(party._id);
},
updateParty: function (party) {
// Make sure only the party owner can delete a party
if (party.owner !== Meteor.userId()) {
throw new Meteor.Error('not-authorized');
}
Parties.update(party._id, party);
}
});
UI: 在这里你会看到和更改党的细节:
<input ng-model="party.name">
<input ng-model="party.description">
<label>Is public</label>
<input type="checkbox" ng-model="party.public">
<button ng-click="save(party)">Save</button>
<button ng-click="reset()">Reset form</button>
<button ui-sref="parties">Cancel</button>
控制器:
$scope.party = $meteor.object(Parties, $stateParams.partyId, false);
$scope.save = function(updatedParty) {
$meteor.call('updateParty', updatedParty);
};
但是这是一个集合时做的工作:
$scope.addParty = function(newParty){
$meteor.call('addParty', newParty);
}
$scope.remove = function(party){
$meteor.call('removeParty', party);
}
当我在教程中这样做时,从客户端调用它,它可以工作,但我希望将其作为方法并更新此文档中的所有字段。我也尝试删除Meteor.methods.updateParty中的所有内容,或者使用$ set,仍然会出现错误。没有什么似乎工作,我尝试。有人看到问题在哪里吗?
谢谢
更新2015年10月29日。 17:51
好吧,当我改变了党的从接收:
$scope.party = $meteor.object(Parties, $stateParams.partyId, false).subscribe('parties');
到:
$scope.party = Parties.findOne($stateParams.partyId);
那么方法调用的作品。但现在不行的是,当我更新页面时,聚会不会再次被提取,就在我第一次来的时候。任何提示?
现在的问题是,这是做正确的方式。
我应该用Parties.findOne取它...或者是罚款$ meteor.object去取和定义,我可以从双方的客户写允许:
Parties.allow({
update: function (userId, party, fields, modifier) {
return userId && party.owner === userId;
}
});
不确定,因为我不使用角度,但我认为有一个无限循环崩溃堆栈。它可以发生在像双角绑定系统中。 – acemtp
@acemtp,谢谢你的评论。好的,什么样的无限循环?我更新了它,当我使用$ meteor.object ..与缔约方.Allow,然后它的工作,但后来我从客户端写入数据库,不知道这是否是正确的方式做... ..但在教程这是一个使用.. – damir