METEOR – Runa: How to use this.Params._ID setting session

I have a route/scoreboard/1, where 1 is not a tranquil id of an object, but a court ID, I want to use it to select the game of the court.

< /p>

I tried this code to set up the session but not load the template. If I delete the event and hardcode the var court, the template will load normally.

this. route('scoreboard',
{

path:'/scoreboard/:_id',

template:'scoreboard',

onBeforeAction: function () {
Session.set('court', this.params._id);
}

}); //route

< p>I found this seems to work. What does not work is this:

var court = Session.get("court");

console.log(court); -> 1

myGame = Games.findOne({court_id: court});

Although this works:

< /p>

myGame = Games.findOne({court_id: 1});

Found it!

var court = parseInt(Session.get('court'));

This worked for me:

$meteor create test
$cd test
$meteor add iron :router

test.js:

if (Meteor.isClient) {
Template.scoreboard.id = function() {
return Session.get('court');
}
}

Router.route('/scoreboard/:_id', {
name: ' scoreboard',
path:'/scoreboard/:_id',
template:'scoreboard',
onBeforeAction: function () {
Session.set('court', this .params._id);
}
});

test.html:




Then go to localhost:3000/scoreboard/123.

I have a route/scoreboard/1, where 1 is not an object of tranquility id, but a court ID, I want to use it to select the game of the court.

I tried this code to set the session but not load the template. If I delete the event and hardcode the var court , The template will load normally.

this.route('scoreboard',
{

path:'/scoreboard/:_id',

template:'scoreboard',

onBeforeAction: function () {
Session.set('court', this.params._id);
}

}); //route

I found this seems to work. What does not work is this:

var court = Session.get("court");

console.log(court); -> 1

myGame = Games.findOne({court_id: court});

Although this works:

myGame = Games.findOne({court_id: 1});

Found it!

var court = parseInt(Session.get('court'));

This is for me Useful:

$meteor create test
$cd test
$meteor add iron:router

test.js :

if (Meteor.isClient) {
Template.scoreboard.id = function() {
return Session.get('court');
}
}

Router.route('/scoreboard/:_id', {
name:'scoreboard',
path:'/scoreboard /:_id',
template:'scoreboard',
onBeforeAction: function () {
Session.set('court', this.params._id);
}< br />});

test.html:




Then go to localhost: 3000 / scoreboard / 123.

Leave a Comment

Your email address will not be published.