【发布时间】:2015-08-06 15:31:30
【问题描述】:
大家好,我在使用 meteorJS 时遇到了很多问题,因为当我在服务器端订阅发布时,我似乎无法访问任何客户端的属性。我有一个包含“每日活动”的集合,供我的用户使用,我将尝试将其发布到客户端。但由于某种原因,它在客户端未定义,即使我可以在服务器端执行 console.log 并且它工作正常。
代码如下:
Client side:
communityEvents = new Mongo.Collection("communityEvents");
Meteor.subscribe('communityEventsPub');
Template.communityEvent.helpers({
type: function(){
todaysEvent = communityEvents.find().fetch();
console.log("this is the event " + todaysEvent["type"]);
return todaysEvent.type;
},
event: function(){
todaysEvent = communityEvents.find().fetch();
return todaysEvent.event;
}
});
Server Side:
communityEvents = new Mongo.Collection("communityEvents");
Meteor.publish("communityEventsPub", function(){
console.log(moment().format('l'));
console.log(communityEvents.find({date:moment().format('l')}).fetch());
return communityEvents.find({date:moment().format('l')});
});
【问题讨论】:
标签: javascript web-applications meteor publish-subscribe