无法识别的模式错误
问题描述:
您尝试添加吗?无法识别的模式错误
'名':{ 类型:字符串, 可选:真实, 制服:文本字段 }
在落实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>
);
}
}
答
我碰到同样的问题跑,然后意识到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]
误差为你的。