Meteor 在另一个集合中使用 collection.find()

标签 meteor meteor-autoform meteor-collection2 simple-schema

我需要在另一个集合中进行 collection.find() 。我有一个名为 Orders 的集合。

Orders = new Mongo.Collection('orders')
Orders.attachSchema(new SimpleSchema({
clientId: {
    type: String
  },
  orderDate: {
    type: Date
  }
});

它使用 aldeed:collection2 和 aldeed:simple shema。我用它来使用 aldeed:autoform 创建表单

我想将 allowedValues 放入包含客户端 ID 的 ClientId 字段中。 所以我需要使用 Clients.find() 获取所有客户端 ID。客户是另一个集合。但在客户端上,如果我尝试将 console.log(Clients.find().fetch()) 放入 order.js 集合文件中,它会记录一个空数组,而在服务器上它会记录一个包含所有客户端的数组。我知道对函数的调用是在客户端可用集合之前进行的。但即使将其包装在 Meteor.startup 中也不起作用。有人知道吗?

最佳答案

我猜您想要做的是限制 Order 编辑器中客户端的选择。您可以创建一个如下所示的助手

Template.editOrder.helpers
   clientList: ()->
     Client.find().fetch()

并将此助手与自动表单一起使用

{{> afQuickField name="clientSelected" options=clientList}}

关于Meteor 在另一个集合中使用 collection.find(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34273947/

相关文章:

node.js - Meteor 无法从 MongoDB 检索数据

javascript - meteor 覆盖包中元素的点击事件

mongodb - Meteor 集合不会在启动时自动创建,并且自动表单不会发布到 mongo db

node.js - 如何通过meteorhacks npm正确使用 Node 模块

javascript - meteor @import css : Resource interpreted as Stylesheet but transferred with MIME type text/html:

javascript - MongoDB - 查找今天之前和之后的单个日期

meteor - 如何获取 Meteor AutoForm 中的 fieldValue

javascript - Meteor 自动表单提交和模态驳回

javascript - meteor :应用程序崩溃

javascript - 如何通过 autoValue 将 Meteor.userId() 添加到 SimpleSchema?