【发布时间】:2015-04-28 23:11:03
【问题描述】:
这是我的问题
我已经在 MeteorisServer 和 MeteorisClient 包装器之外声明了我的 Collection。
var Items = new Meteor.Collection("items");
然后我用数组 x 和数组 z 插入我的 Items Collection。
Items.insert({
owner: x,
post_id: z,
draft: true
});
当console.log(Items.find().fetch()) 输出到屏幕服务器端时,我在命令行中看到了这一点。
服务器
{ owner:
[ 'Sneaker of the Week: \n\nThe women\'s Roshe Flyknit multi-color arrives soon. #roshe http://t.co/1Zfothclmz\n',
'Sneaker of the Week:\n\nThe men\'s Roshe Flyknit is now available: http://t.co/frqNCZQbS5 #roshe http://t.co/HOAbnKFUDZ\n',
'Modern comfort. The men\'s Roshe Flyknit is now available: http://t.co/zwTWPMpyYK #roshe http://t.co/l7ZLm67sNC\n',
'A full-fledged phenomenon, her destiny is to change tennis and the culture, one fallen rival at a time. #techpack http://t.co/TksxyQTUpr\n',
'Her youth conceals an aggressive game of precise strikes and high-tempo performances. #techpack http://t.co/khqgKdZsfv\n',
'Always ready, Genie Bouchard is steady crafting her legacy on the tennis court. #techpack http://t.co/U3WTP6Arax\n',
'Sneaker of the Week:\n\nThe men\'s Dunk CMFT is now available: http://t.co/WFFCBNxICZ http://t.co/OByzzLLdlL\n' ],
post_id:
[ 'http://pbs.twimg.com/media/B-f5AF0IcAAQkZY.jpg',
'http://pbs.twimg.com/media/B-eHJ8tIIAAFUgO.jpg',
'http://pbs.twimg.com/media/B-TZZx7IIAAH9EH.jpg',
'http://pbs.twimg.com/media/B-PBNPkCQAAJq0w.jpg',
'http://pbs.twimg.com/media/B-O_zjaCUAEb6Fj.jpg',
'http://pbs.twimg.com/media/B-O9HhQCAAAIxHM.jpg',
'http://pbs.twimg.com/media/B-ApJnQIgAQisgR.jpg' ],
draft: true,
_id: '3GW4oqzNHZw9p6yLQ' },
然后我在服务器端发布这个
// Publish the logged in user's posts
Meteor.publish("posts-recent", function () {
return Items.find({ owner: x });
});
客户
然后在客户端接收它。
Meteor.subscribe('posts-recent');
var newItems = Items.find();
console.log(newItems);
控制台
不幸的是,这只是输出对文件开头声明的空集合的引用。我的客户端似乎根本无法接收这些数据。此外,当我在控制台检查器中搜索项目时,我被告知它是未定义的。那么有人知道我使用发布和订阅的方式是否有任何问题吗?
【问题讨论】:
标签: javascript collections meteor insert publish-subscribe