2017-06-19 110 views
1

您尝试添加吗?无法识别的模式错误

'名':{ 类型:字符串, 可选:真实, 制服:文本字段 }

在落实vazco/uniforms与simpleschema我发现了一个错误。错误消息是,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> 
    ); 
    } 
} 

回答

0

我碰到同样的问题跑,然后意识到ProfileCanidate模式需要对原来的简单模式的schema一个道具,它可以” t分别命名为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]误差为你的。

相关问题