【发布时间】:2017-01-19 15:43:09
【问题描述】:
我的 Iron-router 中定义了以下路由:
this.route("/example/:id", {
name: "example",
template: "example",
action: function () {
this.wait(Meteor.subscribe('sub1', this.params.id));
this.wait(Meteor.subscribe('sub2', <<data of sub1 needed here>>));
if (this.ready()) {
this.render();
} else {
this.render('Loading');
}
}
});
我想在渲染我的实际模板之前等待 sub1 和 sub2。问题是我需要一条数据,它是 sub2 订阅的 sub1 结果的一部分。
如何才能按顺序等待订阅?这样我就可以将等待分成两步,等待我的第一个订阅完成。然后开始第二次订阅,然后设置 this.ready() 来渲染模板?
我想到的一种解决方法是使用 Reactive-Vars 进行订阅,而不使用 Iron-router 提供的 .wait 和 .ready。但我想使用 Iron-router 或 Meteor 本身提供的更方便的解决方案。您知道对此有更好的解决方案吗?
感谢您的回答!
【问题讨论】:
-
难道不能只创建sub3,它采用与sub1相同的参数并返回sub1和sub2的数据吗?
-
我不知道发布函数可以返回两个不同集合的结果?这是真的吗?
-
有趣的事情,非常感谢!
标签: meteor iron-router subscription