0
我有兩個使用相同字段的獨立架構。我試圖創建schemaComponents,以便我可以在一個位置更新兩個模式,但是我得到一個錯誤Error: Invalid definition for school.$ field
。當我使用它。我不確定我在這裏做錯了什麼,我在這個允許的印象之下。重複使用相同字段時的架構錯誤
路徑:SchemaComponents.js
SchemaComponents = {
schools: {
type: [String],
optional: true,
autoform: {
options: [
{label: "School One", value: 'SchoolOne'},
{label: "School Two", value: 'SchoolTwo'},
{label: "School Three", value: 'SchoolThree'},
]
}
}
};
路徑:StudentSchema.js
import from '../components/SchemaComponents.js';
StudentSchema = new Mongo.Collection("studentSchema");
var Schemas = {};
Schemas.StudentSchema = new SimpleSchema({
school: SchemaComponents.schools,
});
StudentSchema.attachSchema(Schemas.StudentSchema);
路徑:TeacherSchema.js
import from '../components/SchemaComponents.js';
TeacherSchema = new Mongo.Collection("teacherSchema");
var Schemas = {};
Schemas.TeacherSchema = new SimpleSchema({
school: SchemaComponents.schools,
});
TeacherSchema.attachSchema(Schemas.TeacherSchema);
我收到服務器錯誤'的ReferenceError:schoolsSchema沒有在路徑defined':'TeacherSchema.js' – bp123
然後您需要將'schoolsSchema'導入到您的'TeacherSchema.js'文件中。 –
好的,所以我已經添加了'從../ components/SchemaComponents.js'導入schoolsSchema;'現在我得到了'錯誤:學校字段的無效定義' – bp123