按名称获取 Meteor 集合 [英] Get Meteor collection by name

查看:31
本文介绍了按名称获取 Meteor 集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我写:

new Meteor.Collection("foos");
new Meteor.Collection("bars");

是否有用于按名称访问这些集合的 API?类似于 Meteor.Collection.get(name),其中 name"foos" 还是 "bars"?我知道我可以写一些类似的东西

Is there an API for accessing those collections by name? Something like Meteor.Collection.get(name), where name is "foos" or "bars"? I know I could write something like

var MyCollections = {
    foos: new Meteor.Collection("foos");
    bars: new Meteor.Collection("bars");
}

然后使用 MyCollections[name],但我更愿意使用现有 API(如果存在).

and then use MyCollections[name], but I'd prefer to use an existing API if one exists.

推荐答案

据我在 collection.js 源中看到的,目前在 api 中没有办法通过name,一旦它已经在服务器上初始化.添加该功能可能并不难.

As far as I can see in the collection.js source there currently is no way in the api to get an existing Collection by name, once it has already been initialized on the server. It probably wouldn't be hard to add that feature.

那么,为什么不 fork Meteor 并提交补丁或创建一个智能包并共享它我敢肯定还有其他人想要相同的功能.

So, why not fork Meteor and submit a patch or create a smart package and share it I'm sure there are others out there who'd like the same feature.

这篇关于按名称获取 Meteor 集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆