简体   繁体   English

流星Collection2更新引发错误

[英]Meteor Collection2 Update throwing errors

I'm using the Collection2 package for integrating a schema and simple validation method for my Meteor app. 我正在使用Collection2包为我的Meteor应用程序集成架构和简单的验证方法。

Inserts are working just fine, erroring appropriately, and inserting when valid as intended. 插入效果很好,可以适当地出错,并且可以按预期的效果插入。 According to the docs, using the update method is pretty much the same but validation errors keep appearing even though everything is valid per the schema. 根据文档,使用update方法几乎相同,但是即使每个架构都有效,验证错误仍会出现。

So for example, I'll submit a new property(an actual home/apartment) that validates against the schema, and it works no problem. 因此,例如,我将提交一个新的属性(实际的房屋/公寓),该属性可以根据模式进行验证,并且可以正常工作。 I'll go to edit that property, change one letter on 1 field, and it errors on various fields. 我将编辑该属性,在1个字段上更改一个字母,然后在各个字段上出错。

I'm kind of at a loss. 我有点茫然。 It's pretty straightforward. 这很简单。 I was updating documents no problem before introducing Collection2, but I don't think it's a problem with the package per se because I know it's in use and actively updated. 在介绍Collection2之前,我没有对文档进行任何更新,但是我认为该包本身不是问题,因为我知道它正在使用并且正在积极更新。 Maybe I need to put this method on the server? 也许我需要将此方法放在服务器上?

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

The Client side JS file: 客户端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});
      }
    });

  });

The Collection: 集合:

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
    }
  }
});

Finally saw the issue.. in the template, the HTML, the placeholder attribute seems to register as a value even though the value attribute has content.. 终于看到了问题。在模板的HTML中,即使value属性包含内容,占位符属性似乎也注册为一个值。

I had: 我有:

<input name="zipcode" type="text" class="form-control" value="{{zipcode}}" placeholder="Enter a Zip Code" />

Changed it to: 更改为:

<input name="zipcode" type="text" class="form-control" value="{{zipcode}}" />

And it worked : ) 它起作用了:)

Not sure if this something that is just known, and I should have known, or a bug. 不知道这是我早该知道的还是错误。 I'll submit it regardless. 无论如何,我都会提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM