Skip to content Skip to sidebar Skip to footer

Grab Attribute Of Current Record For Meteor Method Call

I am working on a project to pull in twitter timeline's for selected teams/players. When I am on the team/_id page, how can I grab an attribute to path through a method? Below is

Solution 1:

You should be able to access all information from the current route using the Router.current() object. In your case you can use Router.current().params._id to get the _id param:

var twitterHandle = Router.current().params._id;

Edits based on your comments below

I did not notice that you were calling the Teams.findOne function twice in your route's data function. Form the looks of it you're already storing the twitter handle in the Teams collection, so you merely need to access the data that's returned by the route.

Template.tweets.helpers({
    twitterData: function() {
        //return the data stored in the callback function of the Meteor method call in the onRendered eventreturnSession.get('twitter');
    }
});

Template.tweets.onRendered(function () {
    //clear any previously stored data making the callSession.set('twitter', null);

    //property of the team document returned by the data function in the route.var twitterHandle = this.data.twitter;

    Meteor.call('getTimeline', twitterHandle, function(err,results){
        if (err) {
            console.log("error", error);
        } else {
            Session.set("twitter", JSON.parse(results.content));
        }
    });
});


Router.route('/teams/:_id', {
    name: 'teamView',
    template: 'teamView',
    data: function(){
        var currentTeam = this.params._id;
        returnTeams.findOne({ _id: currentTeam });
    }
});

<templatename="tweets"><h3>Tweets</h3><divclass="container"><!-- twitterData will be an object, so you'll need to figure out what properties to display and use dot notation//-->
        {{twitterData}}
    </div>
</template>

Post a Comment for "Grab Attribute Of Current Record For Meteor Method Call"