如何使用simpleSchema创建可重用组件

bp123

我可能会以错误的方式思考,因此请随时纠正我的想法。

我正在使用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**
});
弗朗切斯科·佩泽拉(Francesco Pezzella)

您可以将可重用对象移动到另一个文件中,如果您使用的是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,
    // ...
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章