正要槽流星教程,並希望引進的添加,更新方法和刪除功能,所以,我不是直接從客戶端得到與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