Meteor - 用 iron router 返回 2 组数据

Meteor - returning 2 sets of data with iron router

我目前正在使用 iron router 创建一个 Meteor 应用程序,但在返回 2 个数据上下文时遇到问题。

Router.map(function() {
    this.route('account', { 
        path: '/account/:accountId',
    template: 'account',
    data: function(){

    //assigning the data object to self in order to use the 'accountId' route paramter
    var self = this;

        var currentRuns = function(){
            return CmrRuns.find({accountId: self.params.accountId});
        }

        var currerntAccount = function(){
            return CmrAccounts.findOne({accountId: self.params.accountId});
        }

        var current = {runs: currentRuns, account: currentAccount};
        return current;
    }
});

我想做的是从 CmrAccounts 集合中获取帐户信息,并从 CmrRuns 集合中获取运行信息。

我目前遇到 "currentAccount is not defined" 错误。 我已经坚持了 2 天了,不知所措。

你知道我在这里做错了什么吗?或者有其他方法可以在使用 iron router 进行路由时获取 2 组数据吗?

首先检查您的订阅。您可以 运行 在控制台中进行相同的客户端查询并获得您要查找的结果吗?

其次,我会简化数据方法。这应该有效:

data: {
    runs: CmrRuns.find({accountId: this.params.accountId}), 
    account: CmrAccounts.findOne({accountId: this.params.accountId})
  }

不过请注意,.map 已弃用:https://github.com/iron-meteor/iron-router/issues/1503 这可能是许多问题的根源。

我也强烈建议放弃这种方法。看看 FlowRouter 作为替代方案。通过使用模板处理您的订阅和数据,它变得更加整洁,更易于诊断、维护和迁移。此外,维护路由之间的数据状态要容易得多,在构建复杂的 UI 时,您可能 运行 进入这些状态。