需要在meteor上将特定用户的javascript对象(而不是集合)从服务器异步推送到客户端
任何对我的meteor应用程序进行研究的用户(客户机)都会调用meteor方法,当它发现某个东西时(可以通过搜索许多不同的外部API,例如),该方法将异步向该客户机发送结果,并可能将其注入到仅客户端(非持久)集合中。如何传递?通过服务器方法,可以传递错误或结果,而不必来自集合 内部方法:需要在meteor上将特定用户的javascript对象(而不是集合)从服务器异步推送到客户端,meteor,websocket,socket.io,ddp,Meteor,Websocket,Socket.io,Ddp,任何对我的meteor应用程序进行研究的用户(客户机)都会调用meteor方法,当它发现某个东西时(可以通过搜索许多不同的外部API,例如),该方法将异步向该客户机发送结果,并可能将其注入到仅客户端(非持久)集合中。如何传递?通过服务器方法,可以传递错误或结果,而不必来自集合 内部方法: methodName: function (arg1, arg2){ if(arg1 !== 'something'){ throw new Meteor.Error(400, 'Err
methodName: function (arg1, arg2){
if(arg1 !== 'something'){
throw new Meteor.Error(400, 'Error text.')
}
//do something if there is no error here. You don't have to check if there are no errors here as Meteor doesn't jump to DB actions/return a result if there is an error.
return 'result you want to show. Could be an object, string, a document from the DB etc.'
}
你的客户电话
Meteor.call('methodName', arg1, arg2, function (err, res){
if(err){
//do something with the err
} else {
//do something with the result
}
});
下一次,请在问问题之前检查一下。干杯。谢谢你的回答,但我想你不明白我的问题。在meteor上调用方法当然很简单。。。正如我所解释的,在我的案例中,客户机告诉服务器开始做一些事情,同时听取服务器Anwser(他们可以是任何东西,任何时间和多次,比如socket io)并将其添加到客户机(=模板)。它是异步的,服务器调用客户机,所有这些过程都必须特定于meteor用户。干杯