问题描述
Meteor的初学者。
Beginner at Meteor. Just learning how everything works so bear with me.
一切都在一个文件中正常工作,但安装 iron:router
有一个多页面的应用程序,我意识到,最好有独立的客户端和服务器文件。不幸的是,现在我无法同步服务器和客户端之间的集合。
Everything was working fine in one file, but after installing iron:router
to have a multi-page application, I realized that it's better to have separate client and server files. Unfortunately, now I'm having trouble syncing the collection between the server and the client. I've read tons of tutorials, but nothing is working.
在我的 server.js
文件中:
Streams = new Meteor.Collection("streams");
if (Meteor.isServer) {
Meteor.publish('streams', function () {
return Streams.find();
});
}
在我的 client.js
file:
if(Meteor.isClient) {
Meteor.subscribe("streams");
Template.body.helpers = function(){
return Streams.find();
}
}
调试后,它说Streams不是在客户端中定义。这是怎么回事?如何连接该集合?
After debugging, it says that "Streams" is not defined in the client. What's going on? How do I connect the collection?
推荐答案
经典架构:
lib / streams.js
Streams = new Meteor.Collection("streams");
server / streams.js
Meteor.publish("streams", function () {
return Streams.find();
});
client / streams.js
Meteor.subscribe("streams");
Template.body.helpers({
streams: function(){
return Streams.find();
}
});
这篇关于客户端和服务器之间的共享集合流星的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!