![](/img/trans.png)
[英]Allowing user to type only positive numbers in input box using angularjs
[英]Only allowing user to send input once, MeteorJs
我正在开发一个用户可以预订课程的应用程序,我希望每个用户只能烹饪一次课程。 这是我现在拥有的代码,希望大家对我有所帮助:)
'click #book': function(e,tmpl){
if($.inArray(Session.get('userID'), Courses.find({_id: this._id}, {fields:{attendees: 1}})) === -1){
console.log('You have already booked this course');
}else{
Courses.update(this._id, {$push: {attendees: Session.get('userID')}});
Courses.update(this._id, {$inc: {numberPlaces: -1}});
console.log('You have booked the course');
}
}
如您所见,我在用户集合中记录了用户的ID,并在每次尝试预订课程时检查其ID是否已存在。
谢谢 !
如果事件处理程序中的上下文是课程文档,则可以执行以下操作:
if (_.contains(this.attendees, Meteor.userid()))
console.log('Already booked!');
否则,您可以在选择器中进行检查:
if (Courses.findOne({_id: this._id, attendees: Meteor.userid()}))
console.log('Already booked!');
如果会话变量Meteor.userid()实际上是指另一个用户,则将其替换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.