[英]get collection from client in meteor/node js
我正在嘗試使用流星從客戶端獲取一個集合。
來自客戶:
Template.mapBody.onCreated(function() { var date = this.subscribe("friendUsers"); for (x in date) { console.log(x); } });
從服務器:
if (Meteor.isServer){ Meteor.publish("friendUsers", getFriendUsers); function getFriendUsers() { return Ski_Stations.find(); } }
我在控制台中什么也沒得到。 有人對此問題有想法嗎?
從流星文檔中-Meteor.subscribe返回一個訂閱句柄,這對於停止或查看訂閱是否准備好非常有用。 但是在這種情況下,我不確定這是您想要的。 我認為您將要像這樣迭代集合。
var friendCursor = friendUsers.find();
var friend;
while ( friendCursor.hasNext() ) {
friend = friendCursor.next();
console.log( friend.somefieldhere );
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.