如何正确使用流星铁路由器waitOn?

how to properly use meteor's ironRouter waitOn?

我的 mongo collection 中有大约 6000 个文档,我需要在应用程序启动时将其加载到 meteor 客户端中。 在我的路线中(位于 app/client 下),我有这个:

Router.map(function() {
    this.route('home', {
        path: '/',
        template: 'dashboardWrapper',
        waitOn: function() {
            return Meteor.subscribe('nasdaq');
        },
        cache: true
    });
});

我的 dashboardWrapper 模板如下所示:

<template name="dashboardWrapper">
    {{#if Template.subscriptionsReady}}
        {{> dashboard}}
    {{/if}}
</template>

My dashboard template looks like this:

<template name="dashboard">
    <div class="container">
        <h2>Priority - 1 Incidents Over Time</h2>

        <div class="row">
            <div id="yearly-bubble-chart" class="dc-chart">
                <strong>Yearly Performance</strong> (radius: fluctuation/index ratio, color: gain/loss)
            </div>
        </div>

        <div class="row">
            <div id="gain-loss-chart">
                <strong>Days by Gain/Loss</strong>
                <a class="reset" href="javascript:gainOrLossChart.filterAll();dc.redrawAll();" style="display: none;">reset</a>

                <div class="clearfix"></div>
            </div>

            <div id="quarter-chart">
                <strong>Quarters</strong>
                <a class="reset" href="javascript:quarterChart.filterAll();dc.redrawAll();" style="display: none;">reset</a>

                <div class="clearfix"></div>
            </div>

            <div id="day-of-week-chart">
                <strong>Day of Week</strong>
                <a class="reset" href="javascript:dayOfWeekChart.filterAll();dc.redrawAll();" style="display: none;">reset</a>

                <div class="clearfix"></div>
            </div>

            <div id="fluctuation-chart">
                <strong>Days by Fluctuation(%)</strong>
                <span class="reset" style="display: none;">range: <span class="filter"></span></span>
                <a class="reset" href="javascript:fluctuationChart.filterAll();dc.redrawAll();" style="display: none;">reset</a>

                <div class="clearfix"></div>
            </div>
        </div>

        <div class="row">
            <div id="monthly-move-chart">
                <strong>Monthly Index Abs Move & Volume/500,000 Chart</strong>
                <span class="reset" style="display: none;">range: <span class="filter"></span></span>
                <a class="reset" href="javascript:moveChart.filterAll();volumeChart.filterAll();dc.redrawAll();"
                   style="display: none;">reset</a>

                <div class="clearfix"></div>
            </div>
        </div>

        <div class="row">
            <div id="monthly-volume-chart">
            </div>
            <p class="muted pull-right" style="margin-right: 15px;">select a time range to zoom in</p>
        </div>

        <div class="row">
            <div>
                <div class="dc-data-count">
                    <span class="filter-count"></span> selected out of <span class="total-count"></span> records | <a
                        href="javascript:dc.filterAll(); dc.renderAll();">Reset All</a>
                </div>
            </div>
            <table class="table table-hover dc-data-table">
            </table>
        </div>

        <div class="clearfix"></div>

    </div>
</template>

Meteor.client 的相关部分如下所示:

if (Meteor.isClient) {

  var ndx,data;

  Template.dashboardWrapper.onCreated( function() {
    var template = this;
    template.subscribe("nasdaq");
  });

  Template.dashboard.onCreated( function() {
          data = Nasdaq.find().fetch();
          ndx = crossfilter(data);
  });

    Template.dashboard.onRendered(function(){

        var self = this;
        self.subscribe("nasdaq", function() {
            self.autorun(function() {
                data = Nasdaq.find().fetch();
            });
        });

我对此的期望是,仪表板模板会等到纳斯达克 collection 的所有数据都加载完毕。 发生的事情绝对没有 - 没有数据也没有错误。

如果我一起删除 ironRounter,然后刷新,我可以获得几十条记录(总共 6000 条)。 有没有办法可靠地强制应用程序等待每个文档加载完毕?

在加载当前模板之前尝试订阅,可能会有效。

Router.route('/dashboardWrapper/:_id', {
    name: 'dashboardWrapper',
    waitOn: function () {
        return [
            Meteor.subscribe('nasdaq')
        ];
    },
    data: function () {
        return Nasdaq.findOne(this.params._id);
}
});