我可能会以错误的方式思考这个问题,所以请随时纠正我的想法。
我使用的是simpleSchema,我有一段代码,用于多个架构。有没有办法创建一个单独的组件并将其导入每个模式,这样当我需要更新组件时,我不必在多个位置更新它?
路径:resuableComponent
type: String,
optional: true,
autoform: {
type: "select",
options: function () {
return [
{label: "School logo 1", value: 'url'},
{label: "School logo 2", value: 'url'},
{label: "School logo 3", value: 'url'},
];
},
}
路径:studentCollection.js
Schemas.Student = new SimpleSchema({
studentUserId: {
type: String,
},
school: {
type: String,
optional: false
},
**resuableComponent**
});
路径:teacherCollection.js
Schemas.Teacher = new SimpleSchema({
teacherUserId: {
type: String,
},
school: {
type: String,
optional: false
},
**resuableComponent**
});
答案 0 :(得分:1)
如果您使用的是SimpleSchema,则可以将可重用对象移动到应在客户端和服务器上都可见的其他文件中。
基于您的问题的示例:
lib/schema-components.js
:
SchemaComponents = {
school: {
type: String,
optional: false
},
// ...
// more reusable components here
};
someCollectionFile.js
:
Schemas.Student = new SimpleSchema({
studentUserId: {
type: String
},
school: SchemaComponents.school,
// ...
});