【问题标题】:Meteor DDP Publication/SubscriptionMeteor DDP 发布/订阅
【发布时间】:2018-03-11 01:42:47
【问题描述】:

我已经设法通过 DDP 连接了 2 个应用程序,但我有点不确定如何从源服务器发布数据。

这是我在客户端上尝试的:

Template.Dashboard.onCreated(function() {
  Meteor.remoteConnection = DDP.connect('http://localhost:3030');
  this.subscribe('templatePublication', {
    connection: Meteor.remoteConnection
  });
});

这应该是调用源服务器上的发布。它没有抛出任何错误,但同时它没有生成任何文档,因为发布是一个简单的 Collection.find({});

只是好奇我是否遗漏了什么……

【问题讨论】:

    标签: javascript meteor ddp


    【解决方案1】:

    我解决了这个问题!看来我把它复杂化了。看起来你必须这样做(这都是在客户端):

    import { DDP } from 'meteor/ddp-client'
    
    var remote = DDP.connect('http://localhost:3030/');
    Templates = new Meteor.Collection('templates', remote);
    
    Template.Dashboard.onCreated(function(){ 
      remote.subscribe('templatePublication');
    });
    
    Template.Dashboard.helpers({
      listTemplates: ()=>{
        return Templates.find();
      }
    });

    【讨论】:

    • onDestroyed 处理程序中停止订阅也是值得的
    猜你喜欢
    • 2016-11-29
    • 2017-11-30
    • 2013-11-18
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多