按名称获取流星集合 [英] Get Meteor collection by name
问题描述
假设我写:
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已经存在,则api中就无法通过名称获取现有的Collection.在服务器上初始化.添加该功能可能并不难.
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.
所以,为什么不分叉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.
这篇关于按名称获取流星集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!