mardi 24 mars 2015

Reinitializing code in Meteor


I started writing a Meteor app today, for an eCommerce site. This is some code in my basic.js file.



Router.route("/shop", function () {

this.layout("shop");
this.render("catalog");

});


When /shop is rendered, some code inside of shop.js is executed:



Template.shop.rendered = function () {
if ($("figure").hasClass("selected")) {
var
productSelected = $("figure.selected"),
productPrice = productSelected.data("price"),
productTitle = productSelected.data("product"),
productLocation = productSelected.find("a").attr("href");

$(".product-title").html(productTitle);
$(".product-cost").html(productPrice);
$(".content__info__title--overview").find("a").attr("href", productLocation);
}
});


Now, this works perfectly fine when the app loads, but when I visit a different route and come back, the none of the code in shop.js work. I'm not sure if I'm doing something wrong, but I'd love some pointers.





Aucun commentaire:

Enregistrer un commentaire