2015-11-02 86 views
1

下面这是我收集的代码流星的pub/sub问题

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 
    }}); 
}); 

我必须做一些订阅还有什么地方呢?

+0

你的发布函数是什么样的? –

+0

只需更新我的问题。 – mohsinali1317

回答

1

您的问题是在这一段代码:

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

调用此页面加载时。此时,Teams集合在客户端仍然是空的。您需要等待数据准备就绪。由于您在铁路路由器中使用waitOn,因此只需将此代码移动到onRendered回拨即可。

+0

onRendered在模板文件中?像Template.ABC.Rendered?但我在收藏中定义它。 – mohsinali1317

+0

我修好了很多。 – mohsinali1317