Javascript 如果找不到文档,则不插入,而是向上插入
我需要的是检查公司是否未添加名称插入公司名称,否则更新公司名称。在我的项目中,注册后的用户可以完全完成配置文件。当用户填写“公司名称”输入并点击保存按钮时,公司名称应添加到公司列表中,如果用户更改了公司名称,也应从公司列表中更改。这是我的密码 用户表单html:Javascript 如果找不到文档,则不插入,而是向上插入,javascript,validation,meteor,input,Javascript,Validation,Meteor,Input,我需要的是检查公司是否未添加名称插入公司名称,否则更新公司名称。在我的项目中,注册后的用户可以完全完成配置文件。当用户填写“公司名称”输入并点击保存按钮时,公司名称应添加到公司列表中,如果用户更改了公司名称,也应从公司列表中更改。这是我的密码 用户表单html: <template name="userFormEdit"> <form class="form new-company"> <div class="form-group"> &
<template name="userFormEdit">
<form class="form new-company">
<div class="form-group">
<label for="companyName">Comapany Name</label>
<input type="text" class="form-control" name="companyName" id="companyName" placeholder="" value="{{companyName}}">
</div>
</form
</template>
<div class="container-fluid text-center bg-grey">
<h2>Portfolio</h2>
<h4>What we have created</h4>
<div class="row text-center">
{{ #each companyProfile }}
{{> companyView }}
{{/each }}
</div>
</div>
</template>
<template name="companyView">
<div class="col-sm-4">
<div class="thumbnail">
<img src="..." alt="Paris">
<p><strong>{{companyName}}</strong></p>
<p>Yes, we built Paris</p>
</div>
</div>
</template>
Meteor已内置用于收藏。你可以用这个 我认为在服务器端使用SQL查询可以更好、更容易地完成此检查。用户单击“保存”按钮,将表单数据发送到服务器,然后您的php(或其他)脚本将公司名称插入或替换到数据库中。@Banzay他使用Meteor wich在服务器上使用Javascritp(nodejs)并在数据库中使用Mongo No SQL,这是一个很酷的框架=dn我不确定是否理解这个问题。你不能用
upsert
代替update吗?你说的“两件事”是什么意思?
currentUserProfile = new Meteor.Collection('userprofile');
//In client
Template.userFormEdit.events({
'submit .new-company' : function(event){
var companyNameVar = event.target.companyName.value;
currentUserProfile.update(this._id,{$set: {companyName: companyNameVar}});
}
});
Template.homepage.helpers({
companyProfile: function(){
return currentUserProfile.find();
}
});