[英]Meteor Collection2 Update throwing errors
我正在使用Collection2包为我的Meteor应用程序集成架构和简单的验证方法。
插入效果很好,可以适当地出错,并且可以按预期的效果插入。 根据文档,使用update方法几乎相同,但是即使每个架构都有效,验证错误仍会出现。
因此,例如,我将提交一个新的属性(实际的房屋/公寓),该属性可以根据模式进行验证,并且可以正常工作。 我将编辑该属性,在1个字段上更改一个字母,然后在各个字段上出错。
我有点茫然。 这很简单。 在介绍Collection2之前,我没有对文档进行任何更新,但是我认为该包本身不是问题,因为我知道它正在使用并且正在积极更新。 也许我需要将此方法放在服务器上?
任何帮助,将不胜感激。 谢谢!
客户端JS文件:
Template.propertyEdit.events({
'submit form': function(e){
e.preventDefault();
var property_details = {
name: $(e.target).find('[name=name]').val(),
address: $(e.target).find('[name=address]').val(),
city: $(e.target).find('[name=city]').val(),
state: $(e.target).find('[name=state]').val(),
zipcode: $(e.target).find('[name=zipcode]')
}
Properties.update(this._id, {$set: property_details}, function(error,result){
if(error){
for(var i=0; Properties.simpleSchema().namedContext().invalidKeys().length > i; i++ ){
throwError(Properties.simpleSchema().namedContext().invalidKeys()[i].message);
}
}else{
alert("Property details updated");
Router.go('propertyOverview', {_id: result});
}
});
});
集合:
Properties = new Meteor.Collection2('properties', {
schema: {
name: {
type: String,
label: "Property Name",
min: 1
},
address: {
type: String,
label: "Address",
min: 1
},
city: {
type: String,
label: "City",
min: 1
},
state: {
type: String,
label: "State",
min: 2,
max: 2
},
zipcode: {
type: String,
label: "Zip Code",
min: 5,
max: 11
},
userId: {
type: String,
label: "User Id",
min: 8
}
}
});
终于看到了问题。在模板的HTML中,即使value属性包含内容,占位符属性似乎也注册为一个值。
我有:
<input name="zipcode" type="text" class="form-control" value="{{zipcode}}" placeholder="Enter a Zip Code" />
更改为:
<input name="zipcode" type="text" class="form-control" value="{{zipcode}}" />
它起作用了:)
不知道这是我早该知道的还是错误。 无论如何,我都会提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.