Created
September 30, 2019 16:00
-
-
Save harryadel/4a406afc52b873cd60ea3b0feecd05d0 to your computer and use it in GitHub Desktop.
Meteor Blaze Shopping Cart Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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