我已成功通过 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/