MeteorCast #3: How To Use Session Variables in Meteor.JS
Here it is, the third MeteorCast.
Notes
HTML
<body>
</body>
<template name="newRental">
<h1>New Rental</h1>
<input type="button" value="New Rental" class="new_rental btn btn-primary" />
<div class="rental_form">
<input type="text" class="rental_name" placeholder="Name" />
<input type="text" class="rental_make" placeholder="Make" />
<input type="text" class="rental_model" placeholder="Model" />
<input type="submit" class="rental_submit" />
</div>
</template>
<template name="selectedRental">
<p>
You have selected
</p>
<p>
No rental selected...
</p>
</template>
<template name="airplanes">
<table class="table table-striped">
<tr>
<th>Name</th>
<th>Make</th>
<th>Model</th>
<th></th>
</tr>
<tr class="rental">
<td></td>
<td></td>
<td></td>
<td><a href="#" class="delete btn btn-danger">Delete</a></td>
</tr>
</table>
</template>
JS var Airplanes = new Meteor.Collection("airplanes");
if (Meteor.isClient) {
Template.newRental.rendered = function() {
$('.rental_form').hide();
};
Template.newRental.events({
'click .new_rental': function () {
$('.rental_form').toggle();
},
'click .rental_submit': function() {
Airplanes.insert({
name: $('.rental_name').val(),
make: $('.rental_make').val(),
model: $('.rental_model').val()
});
}
});
Template.selectedRental.rental = function() {
return Session.get("selected_rental");
};
Template.airplanes.rentals = function() {
return Airplanes.find({});
};
Template.airplanes.events({
'click a.delete': function(e) {
e.preventDefault();
Airplanes.remove(this._id);
},
'click .rental': function() {
Session.set("selected_rental", this);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}