【问题标题】:How do I reference another collection as a field in a Meteor Schema如何在 Meteor Schema 中引用另一个集合作为字段
【发布时间】:2016-11-27 09:04:44
【问题描述】:

我正在使用流星简单模式和自动生成。我想在另一种模式中引用一种类型的对象。这两个模式是在单独的文件中定义的,我还想使用可能引用的下拉列表填充 autoform,但我不清楚如何执行此操作。

我试过了

venue:{
    type: Venues,
    label: "Venue",
},

venue:{
    type: SimpleSchema.Venues,
    label: "Venue",
},

两者都不起作用

【问题讨论】:

  • @Rohan-Khude 我很清楚这一点,我试图在流星文档和简单模式文档中找到它,这似乎是一项简单的任务(使用 express 和 mongoose 很简单)但不与遇见。这似乎也是许多流星用户需要的问题。堆栈溢出也不是新手,所以我不确定为什么评论。 .

标签: meteor reference schema


【解决方案1】:

首先你必须像这样定义你的架构:

VenueSchema = new SimpleSchema({
 title: {
 type: String,
 label: "Title",
 max: 200
}
})

你可以在另一个模式中声明一个属性 Venue

CustomerSchema = new SimpleSchema({
 venue: {
 type: VenueSchema
 },
 //an array of venues
 venues: {
 type: [VenueSchema],
 minCount: 1
 }
});

看看 simpleSchema 文档的基本用法 -> https://github.com/aldeed/meteor-simple-schema#basic-usage

希望对你有帮助。

【讨论】:

  • 我认为让我感到困惑的部分是这个,这似乎是当我使用这样的结构,然后使用 autoform 时,它提示我在创建客户时创建场所......什么我真正想要的是能够从用户已经创建的现有场所列表中选择场所
  • 您可以在autoValue CustomerSchema = new SimpleSchema({ venue: { type: VenueSchema }, //an array of venues venues: { type: [VenueSchema], minCount: 1, autoValue: function () { return Venues.find({}).fetch() } } }); 中列出您所有的场地物品
猜你喜欢
  • 2014-09-16
  • 2023-03-26
  • 1970-01-01
  • 2021-08-15
  • 2016-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多