【问题标题】:Simple schema array of objects with different schema's具有不同模式的对象的简单模式数组
【发布时间】:2020-01-12 16:34:29
【问题描述】:

Students 架构有一组管理的对象(测试)。没有两个测试是相同的,一个学生可以有多个测试。需要能够插入/更新具有不同模式的 [test] 对象数组。

已尝试将每个测试放入与学生 ID 相关联的自己的集合中,但是有数百个独特的测试会产生数百个集合。最佳做法?

const StudentSchema = new SimpleSchema({
lname: {
        type: String,
        optional: false,
        label: "Last Name",
        max: 100
    },
fname: {
        type: String,
        optional: false,
        label: "First Name",
        max: 100
    },
tests: {
        type: Object,
        blackbox: true,
        optional: true,
    },
}, { tracker: Tracker });

//Tests Schema example 1------------------------

TestADT_Schema = new SimpleSchema({

total_ADT_score_rs: {type: Number, optional: true,},
total_ADT_score_tsc: {type: Number, optional: true,},
qualitative_score: {type: Number, optional: true,},
});

Test_ADT_Schema.attachSchema(ADT_Schema);

//Test Schema example 2 --------------------------

TestWJIVCA_Schema = new SimpleSchema({

GenIntellectualAbility_AE: {type: Number, optional: true,},
  GenIntellectualAbility_GE: {type: Number, optional: true,},
  GenIntellectualAbility_RPI: {type: Number, optional: true,},
  GenIntellectualAbility_SS: {type: Number, optional: true,},
  GFGC_COMPOSITE_AE: {type: Number, optional: true,},
  GFGC_COMPOSITE_GE: {type: Number, optional: true,},
  GFGC_COMPOSITE_RPI: {type: Number, optional: true,},
});

TestWJIVCA_Schema.attachSchema(TestsWJIVCASchema);

每个学生有 1 到 n 个测试,需要将测试嵌套到学生的集合中,但不确定是否可以这样做?

【问题讨论】:

    标签: meteor schema meteor-autoform


    【解决方案1】:

    如果 tests 是一个包含神秘对象的数组,则应将 tests 标记为数组,并将其子对象标记为黑盒对象:

    const StudentSchema = new SimpleSchema({
    lname: {
            type: String,
            optional: false,
            label: "Last Name",
            max: 100
        },
    fname: {
            type: String,
            optional: false,
            label: "First Name",
            max: 100
        },
    tests: Array,
    'tests.$': {
            type: Object,
            blackbox: true,
        },
    }, { tracker: Tracker });
    

    【讨论】:

    • 感谢您的反馈。我将如何去编辑这个[对象]? BrotherField() ...不确定如何实现,文档不多,感谢您对此的任何帮助!
    • 对不起,我不明白你的意思[object]? siblingField(),你能把这部分加到问题中吗?
    猜你喜欢
    • 1970-01-01
    • 2020-03-27
    • 2020-03-10
    • 2021-05-14
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    相关资源
    最近更新 更多