javascript - Meteor DDP 发布/订阅

标签 javascript meteor ddp

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

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

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

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

只是好奇我是否缺少某些东西......

最佳答案

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

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();
  }
});

关于javascript - Meteor DDP 发布/订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49211775/

相关文章:

node.js - 该平台不支持代理

javascript - 文件错误{代码: 5} trying to use absolute file paths with Meteor 1. 4 Cordova

android - 部署 Android 4.2.2 : Use of const in strict mode 时出现 Ionic2 白屏错误

javascript - 使用 $.ajax 调用 php 脚本从服务器上的文本文件读取数据

javascript - 通过在javascript中传递键和值从数组中获取对象

javascript - Meteor:无需用户帐户即可管理数据(尚)

machine-learning - 使用 Dask 在一组服务器上训练 pytorch-lightning 模型的最简单方法是什么?

Meteor DDP 服务器到客户端规范 : strange characters in the beginning

javascript - Angular 等价于 jQuery Submit()

javascript - 使用 jQuery,我能否定位一个元素以仅在父元素悬停时显示其子元素?