Meteor 流星酒吧/订阅

Meteor 流星酒吧/订阅,meteor,simple-schema,Meteor,Simple Schema,这是我的收藏代码 Competitions = new Mongo.Collection("competitions"); var CompetitionsSchema = new SimpleSchema({ year: { type: String }, division: { type : String, allowedValues: ['Elite', '1st','2nd','3rd','4th','Intro'] }, tea

这是我的收藏代码

Competitions = new Mongo.Collection("competitions");

var CompetitionsSchema = new SimpleSchema({
  year: {
      type: String
  },
  division: {
      type : String,
      allowedValues: ['Elite', '1st','2nd','3rd','4th','Intro']
  },
  teams:{
      type : [TeamSchema],
      allowedValues: (function () {
         return Teams.find().fetch().map(function (doc) {
            return doc.name;
        });
      }()) //here we wrap the function as expression and invoke it
  }
}); 
在allowedValues函数中

Teams.find为空

在路由器中,我订阅的出版物如下

 this.route('competitions', {
    path: '/admin/competitions',
    layoutTemplate: 'adminLayout',
    waitOn: function () {
        return [
            Meteor.subscribe('teams')
        ];
    }
});
这是我的发布功能

Meteor.publish('teams', function() {
  return  Teams.find({},{sort: {
    points: -1,
    netRunRate : -1
  }});
});

我还需要在其他地方进行订阅吗?

您的问题在于这段代码:

  allowedValues: (function () {
     return Teams.find().fetch().map(function (doc) {
        return doc.name;
    });
  }()) //here we wrap the function as expression and invoke it

当页面加载时,将调用该函数。此时,
团队
集合在客户端仍然是空的。您需要等待数据准备就绪。由于您在iron router中使用的是
waitOn
,只需将此代码移动到
onRendered
回调即可。

您的发布函数是什么样子的?只需更新模板文件中的my question.onRendered即可?比如Template.ABC.Rendered?但我在收藏中定义了它。