流星订阅回调 [英] Meteor subscribe callback

查看:58
本文介绍了流星订阅回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此处的这篇文章

https://dweldon.silvrback.com/common-mistakes

订阅不会被阻止

Subscriptions don't block

该框架的许多方面看起来都很神奇.如此之多以至于它可能 使您忘记网络浏览器的工作方式.举个简单的例子:

Many aspects of the framework seem like magic. So much so that it may cause you to forget how web browsers work. Take this simple example:

Meteor.subscribe('posts');

Meteor.subscribe('posts');

var post = Posts.findOne();

var post = Posts.findOne();

关于帖子将不确定的想法是大约一个原因的根本原因 关于stackoverflow的二十个流星问题.

The idea that post will be undefined is the root cause of roughly one in twenty meteor questions on stackoverflow.

那么为什么不订阅有回调,如果有,为什么流星文人不经常引用它呢?

So then why doesn't subscribe have a callback, and if it does, why isn't it referenced more often by the Meteor literati?

为什么没有:

Meteor.subscribe('posts', function(err, posts){

//when the items/posts actually arrive

}); 

我希望我的问题有意义.

I hope my question makes sense.

推荐答案

也许我没有得到问题,但是Meteor.Subscribe函数具有名为onError和onReady方法的回调.

Maybe I don't get the question, but the Meteor.Subscribe function has callbacks named onError and onReady methods.

可选.可能包括onError和onReady回调.如果一个功能是 传递而不是对象传递,它被解释为onReady回调.

Optional. May include onError and onReady callbacks. If a function is passed instead of an object, it is interpreted as an onReady callback.

来自文档.

例如.

Meteor.subscribe("posts", {
  onReady: function () { console.log("onReady And the Items actually Arrive", arguments); },
  onError: function () { console.log("onError", arguments); }
});

还请检查此 GitHub问题

这篇关于流星订阅回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆