无法识别的架构错误

时间:2017-06-19 01:31:24

标签: reactjs meteor simple-schema

您尝试添加吗?

'name':{     type:String,     可选:true,     制服:TextField   }

尝试使用simpleschema实现vazco/uniforms时出错。错误消息是Invariant Violation: Unrecognised schema: [object Object]。我不确定这个包裹要求的是什么。

路径:Schema

import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
import TextField from 'uniforms-bootstrap3/AutoForm'; // Choose your theme package.

export const ProfileCandidate = new Mongo.Collection('profileCandidate');

const ProfileCandidateSchema = new SimpleSchema({
  'name.first': {
    type: String,
    optional: true,
    uniforms: TextField
  }
});

ProfileCandidate.attachSchema(ProfileCandidateSchema);

路径:Form

import AutoForm from 'uniforms-bootstrap3/AutoForm';
import ProfileCandidateSchema from '../../../../api/profileCandidate/profileCandidate';

export default class CareerHistoryFormPage extends Component {
  constructor() {
    super(...arguments);

    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleSubmit(doc) {
    console.log("Doc: ", doc);
  }

  render() {
    return (
      <div className="paper">
        <AutoForm schema={ProfileCandidateSchema} onSubmit={this.handleSubmit} />
      </div>
    );
  }
}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,然后意识到ProfileCanidate架构需要schema支持原始简单架构,它不能单独命名为ProfileCanidateSchema(其中是我通常使用的语法)。因此,要编辑代码,事情应该更像是这样:

import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
import TextField from 'uniforms-bootstrap3/AutoForm'; // Choose your theme 
package.

export const ProfileCandidate = new Mongo.Collection('profileCandidate');

ProfileCandidate.schema = new SimpleSchema({
  'name.first': {
    type: String,
    optional: true,
    uniforms: TextField
  }
});

ProfileCandidate.attachSchema(ProfileCandidate.schema);

import AutoForm from 'uniforms-bootstrap3/AutoForm';
import ProfileCandidate from 
'../../../../api/profileCandidate/profileCandidate';

export default class CareerHistoryFormPage extends Component {
  constructor() {
    super(...arguments);

    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleSubmit(doc) {
    console.log("Doc: ", doc);
  }

  render() {
    return (
      <div className="paper">
        <AutoForm schema={ProfileCandidate.schema} onSubmit={this.handleSubmit} />
      </div>
    );
  }
}

这应该为您排除Invariant Violation: Unrecognised schema: [object Object]错误。