0

FlowRouter在我的应用程序中使用,并且是 Meteor 的新手。我已经像这样订阅了我的收藏:

Template.PanelEditAbout.onCreated(function() {
    var self = this;
    self.autorun(function() {
        self.subscribe('pages', 'about');
    });
});

我试图在rendered函数中使用订阅,但它不起作用:

Template.PanelEditAbout.rendered = function() {
    page = Pages.findOne({
        slug: 'about'
    });
}

如果我正确,我必须等待订阅可用。我怎样才能做到这一点?我还需要在准备就绪时添加加载消息(或微调器)。我知道如何在 IronRouter 中执行此操作,但不使用 FlowRouter。

4

2 回答 2

3

永远不要订阅onRendered,首先。试试下面的:

Template.PanelEditAbout.onCreated(function() {
  this.subscribe('pages', 'about');
});

Template.PanelEditAbout.onRendered(function() {
  let page = {};

  this.autorun(() => {
    if (this.subscriptionsReady()) {
      console.log('subs ready');
      page = Pages.findOne({
        slug: 'about'
      });
    }

    console.log(page);
  });
});
于 2015-11-17T07:31:54.067 回答
1

如果它是您的出版物的名称,您可以在订阅页面期间使用 onReady。

Template.PanelEditAbout.rendered = function() {
  Meteor.subscribe("page", Yourslug,{
    onReady: function () { console.log("onReady And the Itemns actually Arrive",     arguments); },
    onError: function () { console.log("onError", arguments); }
  });
};

控制台日志只是一个例子。

于 2015-11-17T06:33:23.697 回答