I am trying to get a collection from client using meteor.
From client:
Template.mapBody.onCreated(function() { var date = this.subscribe("friendUsers"); for (x in date) { console.log(x); } });
From server:
if (Meteor.isServer){ Meteor.publish("friendUsers", getFriendUsers); function getFriendUsers() { return Ski_Stations.find(); } }
I get nothing in the console. Does some one have any ideas about this problem?
From the meteor documentation - Meteor.subscribe returns a subscription handle, which is great for stopping or seeing if the subscription is ready. But I'm not sure this is what you want in this case. I think you are going to want to iterate the collection like this..
var friendCursor = friendUsers.find();
var friend;
while ( friendCursor.hasNext() ) {
friend = friendCursor.next();
console.log( friend.somefieldhere );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.