< /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'));
$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:
Scoreboard
id is: {{id}}
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:
Scoreboard
id is: {{id}}
Then go to localhost: 3000 / scoreboard / 123.