Javascript 防止MeteorJS集合中的重复(通过表单)
我通过表单收集数据&使用输入类将其保存到meteor collection(工作正常)。现在,我想防止重复输入“电子邮件”和“类别”组合(用户不能从同一封电子邮件中申请两次类别)。请帮忙Javascript 防止MeteorJS集合中的重复(通过表单),javascript,jquery,html,mongodb,meteor,Javascript,Jquery,Html,Mongodb,Meteor,我通过表单收集数据&使用输入类将其保存到meteor collection(工作正常)。现在,我想防止重复输入“电子邮件”和“类别”组合(用户不能从同一封电子邮件中申请两次类别)。请帮忙 另外,请告诉我如何生成填有姓名的感谢通知 /*Meteor JS File*/ Info = new Meteor.Collection("info"); if (Meteor.isClient) { Template.add_info.events({ 'submit form':
另外,请告诉我如何生成填有姓名的感谢通知
/*Meteor JS File*/
Info = new Meteor.Collection("info");
if (Meteor.isClient) {
Template.add_info.events({
'submit form':function(){
Info.insert({
category:$('.the_item11').val(),
name:$('.the_item1').val(),
mobile:$('.the_item2').val(),
Mail:$('.the_item3').val(),
createdAt: new Date(),
});
if ($.trim($("#uname").val()) === "" || $.trim($("#umobile").val()) === ""){
alert('you did not fill out one of the fields');
return false; }
alert("Thank You For Registering")
}
});
}
/*HTML form*/
<head>
<title>yahaviform</title>
</head>
<body>
<img src="EDMcrowd.jpg" name="CA_5" id="CA_5"/>
<h1 id="reg">Register here</h1>
{{> add_info}}
</body>
<template name="add_info">
<div id="d1">
<form>
<label>You are</label><br>
<select class="the_item11" id="ucat" required>
<option></option>
<option>DJ</option>
<option>Singer</option>
<option>Instrumentalist</option>
<option>Band</option>
</select> <br>
<label>Name</label><br>
<input type="text" class="the_item1" id="uname" required><br>
<label>Mobileno.</label><br>
<input type="tel" class="the_item2" id="umobile" required><br>
<label>EmailID</label><br>
<input class="the_item3" type="email" id="umail" required><br>
<br>
<input type="submit" value="Register">
</form>
</div>
</template>
/*Meteor JS文件*/
Info=新流星收藏(“Info”);
if(Meteor.isClient){
Template.add_info.events({
“提交表单”:函数(){
信息插入({
类别:$('.the_item11').val(),
名称:$('.the_item1').val(),
mobile:$('.the_item2').val(),
邮件:$('.the_item3').val(),
createdAt:新日期(),
});
if($.trim($(“#uname”).val())===“”“| |$.trim($(“#umobile”).val())==“”){
警报(“您没有填写其中一个字段”);
返回false;}
提醒(“感谢您的注册”)
}
});
}
/*HTML表单*/
雅哈夫形
在这里注册
{{>添加信息}
你是
流行音乐播音员
歌手
乐器演奏者
乐队
名称
美孚诺。
EmailID
您可以使用索引:
看看很棒的软件包
meteor autoform
我应该在代码中的什么位置放置此..?&我创建了一个“流星收藏”,而这似乎是“mongo收藏”
db.my_collection.ensureIndex(
{
email: 1,
category: 1
},
{
unique: 1
}
)