Meteor pub/sub issues
以下是我的收藏代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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 is empty.
在路由器中我订阅出版物如下
1 2 3 4 5 6 7 8 9 | this.route('competitions', { path: '/admin/competitions', layoutTemplate: 'adminLayout', waitOn: function () { return [ Meteor.subscribe('teams') ]; } }); |
这是我的发布功能
1 2 3 4 5 6 | Meteor.publish('teams', function() { return Teams.find({},{sort: { points: -1, netRunRate : -1 }}); }); |
我是否也必须在其他地方进行订阅?
您的问题出在这段代码中:
1 2 3 4 5 | allowedValues: (function () { return Teams.find().fetch().map(function (doc) { return doc.name; }); }()) //here we wrap the function as expression and invoke it |
页面加载时调用。那时