在我的应用程序中,我对应用程序的问题进行评分。所以我有3个系列:apps,questions&率。 当我在我的数据库中插入费率时,我还会检查是否已为应用程序回答了所有问题。如果是,我更新当前应用程序的 ratingComplete 属性:
Meteor.methods({
rateApplication: function(rateAttributes){
var user = Meteor.user();
var rateAlready = Rates.findOne({appId: rateAttributes.appId, qId: rateAttributes.qId});
// ... some checks & code ...
if(rateAlready !== undefined)
Rates.remove({_id: rateAlready._id});
rateId = Rates.insert(note);
if(Rates.find({appId:rateAttributes.appId}).count() === Questions.find().count()){
Applications.update({_id:rateAttributes.appId},{$set:{ratingComplete:true}});
}
return rateId;
}
});
除非代码的这部分出现,否则它的效果很好:
if(Rates.find({appId:rateAttributes.appId}).count() === Questions.find().count()){
Applications.update({_id:rateAttributes.appId},{$set:{ratingComplete:true}});
}
如果发生这种情况,则工作已完成,但客户端页面刷新。即使我在我的模板事件中放了一个e.preventDefault()。
任何人都知道为什么以及如何避免这种情况? 非常感谢。