Skip to content

Instantly share code, notes, and snippets.

@harryadel
Created September 30, 2019 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryadel/4a406afc52b873cd60ea3b0feecd05d0 to your computer and use it in GitHub Desktop.
Save harryadel/4a406afc52b873cd60ea3b0feecd05d0 to your computer and use it in GitHub Desktop.
Meteor Blaze Shopping Cart Example
// Rendered DOM
// example.html
<div class="product">
<img src="{{productImageSource}}" />
<h4>Title</h4>
<p>Price {{productPrice}}</p>
<button class="add">+</button>
<input type="number" id="quantity" />
<button class="subtract">-</button>
<span class="subtotal">Subtotal</span>
<div class="actionButtons">
<button>Update</button>
<button>Delete</button>
</div>
</div>
// example.js
Template.example.events({
'click .add'(event, templateInstance) {
let currentValue = $(event.currentTarget)
.parent()
.siblings(".subtotal")
.val() // not sure val() or text()
$(event.currentTarget)
.parent()
.siblings(".subtotal")
.val(currentValue + 1);
},
'click .subtract'(event, templateInstance) {
// same as above except we subtract ofc
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment