Shared Collection Between Client and Server Meteor

后端 未结 3 1542
孤街浪徒
孤街浪徒 2021-01-19 17:23

Beginner at Meteor. Just learning how everything works so bear with me.

Everything was working fine in one file, but after installing iron:router to hav

相关标签:
3条回答
  • 2021-01-19 17:36

    If you use autopublish package, which is by default. You just need to do

    lib/streams.js

    Streams = new Meteor.Collection("streams");

    part.

    0 讨论(0)
  • 2021-01-19 17:39

    Classic architecture :

    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();
      }
    });
    
    0 讨论(0)
  • 2021-01-19 17:51

    You need to define Streams on the client as well.

    if(Meteor.isClient) {
       Streams = new Meteor.Collection("streams"); 
       Meteor.subscribe("streams");
       Template.body.helpers = function(){
         return Streams.find();
       }
    }
    
    0 讨论(0)
提交回复
热议问题