Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template data context not being populated #15

Open
LaughingBubba opened this issue Apr 29, 2015 · 1 comment
Open

Template data context not being populated #15

LaughingBubba opened this issue Apr 29, 2015 · 1 comment

Comments

@LaughingBubba
Copy link

Hi, I'm trying to render the results of an aggregation within a template but it's not working.

The aggregation works based on the console logging, which is an array of the results. The template is being rendered, just not the rows of the table. Have I missed something patently obvious?

Should should the results be a mongodb cursor?

Here's the Meteor method:

colSamples = new Mongo.Collection("sampleCol");

Meteor.methods({
    getSummary: function () {
        var pipeline =
            [
                { $sort: { primaryKey: 1, secondaryKey: 1 } },
                {
                    $group: {
                        _id: { pk: "$primaryKey", sk: "$secondaryKey", pair: { $concat: ["$result1", "$result2"] } },
                        pairFrequency: { $sum: 1 }
                    }
                }
            ];

        console.log(colSamples.aggregate(pipeline));
        return colSamples.aggregate(pipeline);
    }
});

Here's the route:

  this.route('sampleAgg', {
    data: function () { return Meteor.call("getSummary") }
  });

and the template:

<template name="sampleAgg">
    <hr>
    <h2>Sample Aggregate data</h2>

    <table id="s-agg" class="table table-hover table-striped">

            <thead>
                <tr>
                    <th>Prm Key</th>
                    <th>Snd Key</th>
                    <th>Pair</th>
                    <th>Count</th>
                </tr>
            </thead>

            {{#each this}} 
                <tr>
                    <td>{{pk}}</td>
                    <td>{{sk}}</td>
                    <td>{{pair}}</td>
                    <td>{{pairFrequency}}</td>
                </tr>
            {{/each}}

        <tfoot>
        <tr>
          <th>Prm Key</th>
          <th>Snd Key</th>
          <th>Pair</th>
          <th>Count</th>
        </tr>
        </tfoot>

        </table> 

</template>
@wuzhuzhu
Copy link

Maybe the route is in client side, and the Meteor.call on client side is async and not wait for returned values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants